home *** CD-ROM | disk | FTP | other *** search
Wrap
unit fDoc; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Menus, uMenu, uOptions, OleCtrls, OleCtl, uSausage, uRegistry, uText, Printers, Buttons, frstatus, ExtCtrls, TMultiP, uInternetFiles, sauscomb, WinSplit, uFrameRover, fColorPicker, CURLHistory, grids, HTMLEditViewLibrary_TLB, uHotDog4; type {-= MrKistic - 7 October 1997 =-} {-= Inline Rover Stuff =-} TfrmDoc = class(TForm) dlgReplace: TReplaceDialog; popViewMain: TPopupMenu; popMainEdit: TMenuItem; nMainEdit: TMenuItem; popMainCut: TMenuItem; popMainCopy: TMenuItem; popMainPaste: TMenuItem; popMainDelete: TMenuItem; popMainUndo: TMenuItem; popMainRedo: TMenuItem; N20: TMenuItem; Poste_restante: TMenuItem; timActivate: TTimer; timAutoSave: TTimer; popMainPreview: TMenuItem; popEditColor: TMenuItem; rtfDoc: THTMLEditView; popMainHREF: TMenuItem; popPSP: TMenuItem; n9: TMenuItem; popMainFormat: TMenuItem; mnuRelToAbs: TMenuItem; mnuAbsToRel: TMenuItem; n8: TMenuItem; mnuConvertLower: TMenuItem; mnuConvertUpper: TMenuItem; n7: TMenuItem; mnuTagsLowercase: TMenuItem; mnuTagsUppercase: TMenuItem; n6: TMenuItem; mnuTable: TMenuItem; mnuBList: TMenuItem; mnuMacros: TMenuItem; n99: TMenuItem; mnuStripTags: TMenuItem; panButtons: TPanel; spdSyntax: TSpeedButton; spdTag: TSpeedButton; spdGutter: TSpeedButton; spdWordWrap: TSpeedButton; spdFields: TSpeedButton; spdInsert: TSpeedButton; spdFormat: TSpeedButton; btnShowButtons: TSpeedButton; lblDocWeight: TLabel; popMainSmartPaste: TMenuItem; procedure FormClose(Sender: TObject; var Action: TCloseAction); function CheckSave: Word; procedure FormCreate(Sender: TObject); procedure dlgFindFind(Sender: TObject); procedure dlgReplaceFind(Sender: TObject); procedure dlgReplaceReplace(Sender: TObject); procedure FormActivate(Sender: TObject); procedure SetDisplay; procedure Center1Click(Sender: TObject); procedure rtfDocDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); procedure rtfDocSelectionChanged(Sender: TObject; nStart, nEnd: Integer); procedure rtfDocDragDrop(Sender, Source: TObject; X, Y: Integer); procedure popMainEditClick(Sender: TObject); procedure lmdDocMRUClick(Sender: TObject; const aValue: string; var Remove: Boolean); procedure rtfDocMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure rtfDocMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure rtfDocKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure rtfDocEditModeToggled(Sender: TObject; bOverwrite: Wordbool); procedure rtfDocDocumentChanged(Sender: TObject; nAction: Smallint; nChangeAt, nChangeCount: Integer); procedure popViewMainPopup(Sender: TObject); procedure popMainUndoClick(Sender: TObject); procedure popMainRedoClick(Sender: TObject); procedure popMainCutClick(Sender: TObject); procedure popMainCopyClick(Sender: TObject); procedure popMainPasteClick(Sender: TObject); procedure popMainDeleteClick(Sender: TObject); procedure timActivateTimer(Sender: TObject); procedure FormShow(Sender: TObject); procedure timAutoSaveTimer(Sender: TObject); procedure PreviewImageClick(Sender : TObject); function PreviewImage(sFilename : String) : String; procedure spdSyntaxClick(Sender: TObject); procedure spdTagClick(Sender: TObject); procedure spdWordWrapClick(Sender: TObject); procedure spdFieldsClick(Sender: TObject); procedure spdInsertClick(Sender: TObject); procedure spdFormatClick(Sender: TObject); procedure popEditColorClick(Sender: TObject); procedure spdGutterClick(Sender: TObject); procedure popMainHREFClick(Sender: TObject); procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure popHideGutterClick(Sender: TObject); procedure popShowPawsClick(Sender: TObject); procedure popLine0Click(Sender: TObject); procedure popLine1Click(Sender: TObject); procedure popLine2Click(Sender: TObject); procedure popLine3Click(Sender: TObject); procedure popLine4Click(Sender: TObject); procedure popPSPClick(Sender: TObject); procedure mnuRelToAbsClick(Sender: TObject); procedure mnuAbsToRelClick(Sender: TObject); procedure mnuConvertLowerClick(Sender: TObject); procedure mnuConvertUpperClick(Sender: TObject); procedure mnuTagsLowercaseClick(Sender: TObject); procedure mnuTagsUppercaseClick(Sender: TObject); procedure mnuTableClick(Sender: TObject); procedure mnuBListClick(Sender: TObject); procedure rtfDocRequestURL(Sender: TObject; var bDispatched: WordBool; var strURL: WideString; var bAccepted: WordBool); procedure rtfDocRequestFont(Sender: TObject; var bDispatched: WordBool; var strFont: WideString; var bAccepted: WordBool); procedure rtfDocRequestSound(Sender: TObject; var bDispatched: WordBool; var strSound: WideString; var bAccepted: WordBool); procedure rtfDocRequestPicture(Sender: TObject; var bDispatched: WordBool; var strPicture: WideString; var bAccepted: WordBool); procedure rtfDocRequestJava(Sender: TObject; var bDispatched: WordBool; var strJava: WideString; var bAccepted: WordBool); procedure rtfDocRequestHTML(Sender: TObject; var bDispatched: WordBool; var strHTML: WideString; var bAccepted: WordBool); procedure rtfDocRequestDirectory(Sender: TObject; var bDispatched: WordBool; var strDirectory: WideString; var bAccepted: WordBool); procedure rtfDocSyntaxObjectChanged(Sender: TObject; nType: Smallint; const strPrimary, strSecondary: WideString); procedure mnuStripTagsClick(Sender: TObject); procedure rtfDocRequestColor(Sender: TObject; var bDispatched: WordBool; var Color: Cardinal; var bAccepted: WordBool); procedure btnShowButtonsClick(Sender: TObject); procedure lblDocWeightMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure popMainSmartPasteClick(Sender: TObject); private { Private declarations } bFirstLoaded : Boolean; bSetup: Boolean; bActive: Boolean; sDocFileName: String; sBackupFileName: String; { Find and Replace } iLastFind: Integer; iReplaceCount: Integer; iUntitledCount: Integer; //iChildNum: Integer; { Spell Check } iSpellStart, iSpellEnd: Integer; iSpellPos: Integer; { Remote File Editing } //sPWD: String; //sRemoteFileName: String; //tInternetFileInfo: FTP_FILE_INFO; //tInternetSiteInfo: FTP_SITE_INFO; //sInternetSiteName: String; sInternetFileName: String; bInternet: Boolean; tInternetServer: FTP_SITE_INFO; { Right Click Menu } tCurrentElement: TElementDetails; { Document updating } bDocDirty: Boolean; { Rover updating } bRoverDirty: Boolean; { Kin's Madness } Document: Variant; //Syntax: Variant; procedure ResizeRoverToolbar(bLargeView : Boolean); procedure RefreshDocumentWeight; procedure WMMOVE(var Message: TWMMOVE); message WM_MOVE; procedure WMSIZE(var Message: TWMSIZE); message WM_SIZE; procedure MacroMenuClick(Sender : TObject); procedure SetupMacroMenu; function GetSelText: String; procedure SetSelText(sText: String); function GetDocText: String; procedure SetDocText(sText: String); function GetDocHead: String; procedure SetDocHead(sText: String); procedure OpenHDXFile(sFileName: String); function GetPreviewFileName: String; function CheckDirty: Boolean; //Right Click on Main Edit View procedure MainViewRightClick(X, Y: Integer); procedure DocEditTag; procedure ClearCurrentElement; { Spell Checker } procedure CorrectWord(Sender: TObject); //function FileName: String; procedure SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText,sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject); procedure InsertImage; procedure HideRover; //procedure RecentFilesItemClick(Sender: TObject); {Hint} //procedure SetChildNum(I: Integer); {Hint} function ParseForFont(sText: String): THTMLFont; procedure AddToSelText(sText: String); procedure KillTmpFile; //function CleanSaveAsName(sName, sDefExt: String): String; {Hint} //procedure AddToRecent; procedure HideToolbarShit(bOnlySelectionChanged : Boolean); function GetDocLength: Integer; procedure AutoSave; procedure PasteFromClipboard(Key : word); procedure CopyToClipboard(key : word); procedure DisplayFileDialog(sFilter, sInitialDir : String; var Dispatched : WordBool; var Name : WideString; var Accepted : WordBool); procedure DisplayGutterPopup(X, Y : Integer); function LoadDocumentServer(bFailedOnce : Boolean) : Boolean; protected { Protected declarations } public { Public declarations } //MyPointer: TfrmDoc; //Kin's replacements procedure DocQuickColor(sColor : String); function GenerateTable(sTabledata : String) : String; procedure BuildFontTag(tmpFont: THTMLFont; var sBegin, sEnd: String); function GetNextWordPos(iPos : Integer) : Integer; function GetPrevWordPos(iPos : Integer) : Integer; function GetNextLinePos(iPos : Integer) : Integer; function GetPrevLinePos(iPos : Integer) : Integer; procedure ReplaceText(iStartPos, iLength : Integer; sReplaceText : String); procedure AddText(sText, sEnd: String; bSkipRemoval: Boolean); virtual; { Form Focus } procedure GotFocus; virtual; function GetTagAtScreenCoords(tPos: TPoint): String; function SelStart: LongInt; function SelEnd: LongInt; function SelLength: LongInt; function Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt; procedure InsertText(sText: String; iPos: LongInt); procedure SelectAll; procedure SetCursorPos(iPos: Integer); procedure SetSelection(iStart, iLength: Integer); function GetWordAtPos(iPos: Integer; var iStart, iEnd: Integer): String; function GetNextTextBlock(var iStart: Integer): String; function GetNextTag(var iStart: Integer): String; function CreateTagsDropText(Source: TObject; sHighlighted : String):string; { EditView Shite } procedure UpdateTagColors; procedure UpdateSyntax; {colours} procedure LoadSyntaxColours(Document : THTMLEditView); { Document Parsing Fucntions } function GetTextRange(iStart, iLength: Integer): String; //Get Head positions function FindDocHead(var iStart, iEnd: Integer): Boolean; procedure FindMatchingCharacter(iPosition : Integer); //Return HTML Element function GetElementAt(iPosition: Integer; var iStart: Integer; var sElement: String): Variant; function SniffElements(sResult: TStringList; bIncludePositions: Boolean): Integer; function PublishFields : Integer; procedure PublishAutoFields; procedure InsertPublishField; //Style Sheets procedure DocStyle(sStyleTag : String); { Form Main menu item shit } procedure Save; virtual; procedure SaveAs; virtual; function DocSaveAsRemote: Boolean; //procedure DocExportToText; procedure StripTags; procedure DocReplace; procedure InsertLink(Mode: modeInsert); procedure InsertLine; procedure InsertTable; function CanUndo: Boolean; function GetUndoCount : Integer; function GetNextUndoText : String; function GetUndoItemText(Index : Integer) : String; procedure UndoTo(Index : Integer); function GetNextRedoText : String; function CanRedo: Boolean; function GetRedoCount : Integer; function GetRedoItemText(Index : Integer) : String; procedure RedoTo(Index : Integer); procedure UpdateBodyTag(sBodyTag: String); virtual; function GetBodyTag : String; procedure DocInsert(Mode: modeInsert); procedure DocCut; procedure DocCopy; procedure DocPaste; procedure DocPasteTable; procedure DocPasteLeftAligned; procedure DocUndo; procedure DocRedo; procedure DocDelete; procedure DocFind; procedure DocFindF3; procedure DocFont(bFromRightClick : Boolean); procedure DocBold; procedure DocBody; procedure DocItalic; procedure DocUnderline; procedure DocPara; procedure DocBreak; procedure DocNOBR; procedure DocCenter; procedure DocPrintSetup; procedure DocPrint; procedure DocBigFirst; procedure DocPreview; function DocPreviewWithBrowser(sBrowser: String): Boolean; function DocPreviewWithLastBrowser : Boolean; procedure DocHeading(iHeading: Integer); procedure OpenDoc(sFileName: String); //procedure InternetOpenDoc(sSiteName, sFileName, sRemoteFileName: String); procedure InternetOpenDoc(sLocalFile, sRemotePath: String; tInfo: FTP_SITE_INFO); procedure OpenTemplate(sFileName: String); procedure QuickLink(sFileName: String); procedure QuickImage(sFileName: String); procedure QuickTable(sTableText: String); procedure DocFrameWizard; procedure DocFaveLink(sFileName, sDesc: String); procedure DocPublish; procedure DocPublishToFileOrScreen; {-= MrKistic - 19 november 1997 =-} {-= new =-} function PublishDocumentInAShouseyManner: Integer; function DocPublishAndSave : Integer; //silent - used from frmUpload procedure InsertList; {procedure BullList; procedure NumList;} procedure DocList; procedure DocDefList; procedure DocComment; procedure DocDate; procedure DocHotdogVersion; procedure DocCurrentFilename; procedure DocWindowsVersion; procedure DocUserName; procedure DocCompanyName; procedure DocEmbeded; procedure DocProperties; procedure DocMeta; procedure DocColor; //Can't do this yet - kin procedure DocInsertTarget; function DocConvertExtChar: Integer; function DocConvertTagCase(bPublishing, bUppercase : Boolean) : Integer; procedure DocConvertCase(bUpperCase : Boolean); function ReplaceAll(sFind, sReplace: String): Integer; function DocConvertSlash: Integer; function DocConvertCR(bSelText : Boolean) : Integer; procedure PartnerButton; { Spell Checker } function GetNextSpellWord: String; procedure SelectSpellWord; procedure CorrectSpellWord(sWord: String); procedure CheckSpelling; procedure ShowThesaurus; //procedure BeginSpelling; { Form Elements } procedure FormCheckBox; procedure FormTextBox; procedure FormHidden; procedure FormPassword; procedure FormRadio; procedure FormReset; procedure FormSubmit; procedure FormTextArea; procedure FormList; procedure FormImage; procedure FormWizard; procedure DocRelToAbs; procedure DocAbsToRel; procedure SetFileFormat(DocType: DocEOLType); procedure ToggleFileFormat; procedure Reparse; function GetBookmarks : String; procedure GotoBookmark(sBookmark : String); function GetCurrentLine : Integer; function GetLinePosition(iLine : Integer) : Integer; function GetNextElementPos(iType : Integer; iStart: Integer): Integer; function GetPreviousElementPos(iType : Integer; iStart : Integer) : Integer; function GetDocumentStorageHandle: HGlobal; procedure LoadStorageMemory(hMem: HGlobal); procedure HideSyntaxPicker; published { Published declarations } { example property Digits : byte read FDigits write setDigits; } //property ChildNumber: Integer read iChildNum write SetChildNum; property FileName: String read sDocFileName write sDocFileName; property PreviewFileName: String read GetPreviewFileName; property Dirty: Boolean read CheckDirty; //Kin's replacements property SelText: String read GetSelText write SetSelText; property Text: String read GetDocText write SetDocText; property DocLength: Integer read GetDocLength; { Other properties } property Head: String read GetDocHead write SetDocHead; //Check to see if initialisation went OK property Setup: Boolean read bSetup; property RoverDirty: Boolean read bRoverDirty write bRoverDirty; { Remote Properties } property InternetFile: Boolean read bInternet write bInternet default False; property InternetFileName: String read sInternetFileName write sInternetFileName; end; var frmDoc: TfrmDoc; iBookMarkWidth : Integer; dlgFind : TFindDialog; const INS_NUM_LIST: Integer = 0; INS_B_LIST: Integer = 1; INS_LINE: Integer = 2; INS_FORM: Integer = 3; INS_TABLE: Integer = 4; INS_LINK: Integer = 5; INS_TARGET: Integer = 6; INS_OBJECT_CONTAINER: Integer = 7; INS_IMAGE: Integer = 8; INS_IMG_MAP: Integer = 9; INS_FRAMES: Integer = 10; INS_MARQUEE: Integer = 11; FMT_FONT: Integer = 0; FMT_FONT_COLOUR: Integer = 1; FMT_BIG_FIRST: Integer = 2; FMT_SUPER_SCRIPT: Integer = 3; FMT_SUB_SCRIPT: Integer = 4; FMT_STRIKETHRU: Integer = 5; FMT_BACKGROUND: Integer = 6; FMT_INDENT_IN: Integer = 7; FMT_INDENT_OUT: Integer = 8; FMT_ALIGN_LEFT: Integer = 9; FMT_ALIGN_CENTER: Integer = 10; FMT_ALIGN_RIGHT: Integer = 11; FMT_SYNTAX_CHECK: Integer = 12; FMT_SPELL_CHECK: Integer = 13; {-= MrKistic - 7 October 1997 =-} {-= Inline Rover Stuff =-} SPLIT_WEB_HEIGHT: Integer = 24; SPLIT_ROVER_HEIGHT: Integer = 10; //Gutter Schtuff LINE_GUTTER_SIZE = 920; NO_LINE_GUTTER_SIZE = 450; NO_GUTTER_SIZE = 100; implementation uses fMain, fMainRover, uRover, fImage, uMDI, fLink, fInsRule, comObj, UPTShellControls, fDlg, fFontDlg, table_wizard, frame_wizard, Clipbrd, fNewOptions, {WinShell,} IniFiles, SSCE, fQuickList, uReadHDX, uFindReplace, Checkfrm, ftxtfrm, hidefrm, passfrm, radiofrm, resetfrm, submitfrm, TextArea, imagefrm, listfrm, uTags, uProject, fComment, frmDocProp, fSpellDlg, fformWiz, fUpload, fIntLink, {fImagePrev,} fEmbed, ThumbNailButton, fPublishField, uPublish,fGrabPage, fDirList, uFileDialogs, FileCtrl, oledrop, fDefList, fMeta, ShellAPI, fThesaurus, {iv,} fRemoteDlg, fPublishMsg, fEditMacro, fImageLab, uMainForm, uDocSize; {$R *.DFM} procedure TfrmDoc.DocStyle(sStyleTag : String); begin AddText(tOptions.TagCase(sStyleTag) + SelText, tOptions.TagCase(sStyleTag), False); end; procedure TfrmDoc.FormClose(Sender: TObject; var Action: TCloseAction); var wrdResult: Word; begin Action := caFree; try if bSetup then begin wrdResult := CheckSave; if (tOptions.ReopenFiles) and (tOptions.RecordingFiles) and (sDocFileName <> '') and (not(InternetFile)) then tOptions.FilesToReopen := tOptions.FilesToReopen + sDocFileName + ','; if wrdResult <> mrCancel then begin try bSetup := False; //-- Sav -- Get rid of any temp preview files lying around. DeleteFile(PChar(GetPreviewFileName)); if bInternet then DeleteFile(sDocFileName); KillTmpFile; HideRover; MainForm.DirtyBird(False); //MainForm.HideShit; Rover.ClearView; if Assigned(MainForm.propSheet) then MainForm.propSheet.Selection := Nil; {if Self.ClassName = 'TfrmDocRover' then begin (Self as TfrmDocRover).FreeRover; Application.ProcessMessages; end;} MDI.RemoveMDIChild(Self); try if Assigned(MainForm.tpnlProjects) then tProject.DocumentClosed(sDocFileName); except end; HotDogSound(INI_SOUNDS_CLOSE); if (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).CheckDocumentState(True); //Document.SetSyntaxManager(Null); finally Action := caFree; end; end else Action := caNone; end else begin try wrdResult := mrOK; if Assigned(MainForm.propSheet) then MainForm.propSheet.Selection := Nil; MDI.RemoveMDIChild(Self); try if Assigned(MainForm.tpnlProjects) then tProject.DocumentClosed(sDocFileName); except end; finally Action := caFree; end; end; ModalResult := wrdResult; except end; end; procedure TfrmDoc.OpenDoc(sFileName: String); begin if ExtractFileExt(sFileName) = '.hde' then OpenHDXFile(sFileName) else if FileExists(sFileName) then begin sDocFileName := sFileName; sBackupFileName := GetTempFile(PChar(GetTempDirectory)); Document.LoadFromFile(sFileName); SetFileFormat(Document.EOLType); rtfDoc.ScrollToTop; //Uncommented by Sav 01-09-97 if Find('<BODY', 0, False, False) > -1 then begin DocBody; //SetCursorPos(Find('<BODY', 0, False, False) + 7); end; //Sav 01-09-97 - find the beginning of the body instead of the end. {if DEBUG_FLAG then ShowMessage('Document succesfully loaded');} if tOptions.BackupFiles then Document.SaveToFile(sBackupFileName); Caption := sFileName; //add tab MDI.AddDocumentTab(ExtractFileName(sFileName), Self); //tProject.AddSnifferDocument(sFileName); bDocDirty := False; bRoverDirty := True; AddToMRU(sFileName); HideToolbarShit(False); end; end; procedure TfrmDoc.InternetOpenDoc(sLocalFile, sRemotePath: String; tInfo: FTP_SITE_INFO); {-= InternetOpenDoc: If parameter is valid filename, open this file =-} {-= sLocalFile: Local copy of remote file =-} {-= sRemotePath: full path to remote file on server =-} {-= tInfo: contains Internet Server Information =-} begin try if FileExists(sLocalFile) then begin tInternetServer := tInfo; InternetFile := True; //-- Sav -- Leave sDocFilename blank so that references are absolute. //sDocFileName := sLocalFile; sInternetFileName := sRemotePath; sBackupFileName := GetTempFile(PChar(GetTempDirectory)); Document.LoadFromFile(sLocalFile); //Document.LoadFromFile(sDocFileName); SetFileFormat(Document.EOLType); rtfDoc.ScrollToTop; if Find('<BODY', 0, False, False) > -1 then SetCursorPos(Find('<BODY', 0, False, False) + 7); if tOptions.BackupFiles then Document.SaveToFile(sBackupFileName); Caption := sInternetFileName; {-= add document tab =-} MDI.AddDocumentTab(sInternetFileName, Self); //tProject.AddSnifferDocument(sInternetFileName); bDocDirty := False; bRoverDirty := True; HideToolbarShit(False); end; except //nada end; end; procedure TfrmDoc.OpenHDXFile(sFileName: String); var sHTMLPath, sHTMLFile: String; begin if FileExists(sFileName) then begin {if DEBUG_FLAG then ShowMessage('Attempting to open document: ' + sFileName);} Status('Converting HotDog Express file...'); sHTMLPath := ExtractFileDir(HotDogExpressPath); sHTMLPath := FilePath(sHTMLPath, 'HTMLFiles'); sHTMLFile := ExtractFileName(sFileName); sHTMLFile := StripFileExtension(sHTMLFile) + '.html'; sHTMLFile := FilePath(sHTMLPath, sHTMLFile); WriteWholeFile(sHTMLFile, ReadHDXFile(sFileName)); if FileExists(sHTMLFile) then begin sDocFileName := sHTMLFile; sBackupFileName := GetTempFile(PChar(GetTempDirectory)); Document.LoadFromFile(sHTMLFile); SetFileFormat(Document.EOLType); //rtfDoc.ScrollToTop; if Find('</BODY>', 0, False, False) > -1 then begin SetCursorPos(Find('</BODY>', 0, False, False) - 2); end; end else MessageDlg('An error has occurred while converting your HotDog Express file.', mtError, [mbOK], 0); {if DEBUG_FLAG then ShowMessage('Document succesfully loaded');} if tOptions.BackupFiles then Document.SaveToFile(sBackupFileName); bDocDirty := False; bRoverDirty := True; Caption := sHTMLFile; //add tab MDI.AddDocumentTab(ExtractFileName(sHTMLFile), Self); //tProject.AddSnifferDocument(sFileName); AddToMRU(sFileName); HideToolbarShit(False); Status(''); end; end; procedure TfrmDoc.OpenTemplate(sFileName: String); var sTempFile: String; iPos: Integer; begin try begin if FileExists(sFileName) then begin Document.LoadFromFile(sFileName); SetFileFormat(Document.EOLType); PublishAutoFields; //rtfDoc.ScrollToTop; end else begin sTempFile := GetTempFile(PChar(GetTempDirectory)); try Document.Text := DEFAULT_DOCUMENT; SetFileFormat(Document.EOLType); //rtfDoc.ScrollToTop; finally DeleteFile(sTempFile); end; end; bDocDirty := False; iPos := Find('</BODY>', 0, False, False); if iPos > -1 then begin SetCursorPos(iPos - 2); end; sBackupFileName := GetTempFile(PChar(GetTempDirectory)); Caption := 'Untitled'; //Application.ProcessMessages; //add tab MDI.AddDocumentTab(Caption, Self); //tProject.AddSnifferDocument(Caption); HideToolbarShit(False); //Don't want to be able to undo the stuff we just put in. Document.UndoManager.Reset; GotFocus; end except end; end; procedure TfrmDoc.SaveAs; var tDlgSave: TFileDialog; sOldFileName: String; begin //Checkit tDlgSave := TFileDialog.Create(Self); try begin KillTmpFile; //tDlgSave.UseWinDialog := not(tOptions.UseCustomFileDialog); tDlgSave.InitialDir := tOptions.DocumentDirectory; tDlgSave.DefaultExt := tOptions.DefaultDocExtension; tDlgSave.WinOptions := [ofOverwritePrompt, ofHideReadOnly]; tDlgSave.OpenFile := False; tDlgSave.CustomOptions := [ptofOverwritePrompt, ptofHideReadOnly]; tDlgSave.Filter := SAVE_FILTER_; if tDlgSave.Execute then begin //if bInternet then // DeleteFile(sDocFileName); InternetFile := False; tOptions.LastHTMLDir := ExtractFilePath(tDlgSave.FileName); sOldFileName := sDocFileName; sDocFileName := tDlgSave.FileName; Document.SaveToFile(sDocFileName); if tOptions.BackupFiles then Document.SaveToFile(sBackupFileName); bDocDirty := False; Caption := sDocFileName; //MainForm.Draw(True); //change tab MDI.UpdateTabName(Self, ExtractFileName(sDocFileName)); //tProject.UpdateSniffer(MDI.MDIChildIndex(Self), sDocFileName); AddToMRU(sDocFileName); if Assigned(MainForm.tpnlProjects) then tProject.DocumentSavedAs(sOldFileName, tDlgSave.Filename); if tOptions.SaveBrowserRefresh then DocPreviewWithLastBrowser; HideToolbarShit(False); if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).UpdateRover; //MainForm.RefreshDocumentWeight; end; end finally tDlgSave.Free; end; end; procedure TfrmDoc.Save; var sBackup: String; tServer: tWWWServerType; begin try if InternetFile then begin if not(Assigned(frmUpload)) then begin try //-- Sav -- SDocFilename is now '' so make a file to upload. sDocFileName := FilePath(GetTempDirectory,ExtractFileName(ReplaceString(sInternetFileName, '/', '\'))); Document.SaveToFile(sDocFileName); try Screen.Cursor := crHourglass; Application.CreateForm(TfrmUpload, frmUpload); finally Screen.Cursor := crDefault; end; frmUpload.Caption := 'Saving Remote Document...'; frmUpload.IsDocument := True; frmUpload.DocFileName := sDocFileName; frmUpload.InternetFileName := sInternetFileName; tServer.sAddress := tInternetServer.sAddress; tServer.sDirectory := tInternetServer.sDirectory; tServer.sUserName := tInternetServer.sUserName; tServer.sPassword := tInternetServer.sPassword; tServer.iPort := tInternetServer.iPort; tServer.iTimeOut := tInternetServer.iTimeOut; frmUpload.TimeOut := (tInternetServer.iTimeOut div 1000); frmUpload.tServer := tServer; frmUpload.FormStyle := fsStayOnTop; frmUpload.Show; repeat Application.ProcessMessages; until frmUpload.DoneConnect; if frmUpload.Connected then begin if tOptions.BackupFiles then begin sBackup := RemoteFilePath(ExtractRemoteFilePath(sInternetFileName), ExtractRemoteFileName(sInternetFileName) + '.bak'); frmUpload.FTPRenameFile(sInternetFilename, sBackup); end; if frmUpload.Go then bDocDirty := False; if tOptions.SaveBrowserRefresh then DocPreviewWithLastBrowser; if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).UpdateRover; HideToolbarShit(False); end; finally frmUpload.Close; frmUpload.Free; frmUpload := Nil; end; end; end else begin if Length(sDocFileName) > 0 then begin //sBackupFileName := FilePath(ExtractFileDir(sDocFileName), '~hd$' + ExtractFileName(sDocFileName)); //sBackup := FilePath(ExtractFileDir(sDocFileName), 'Backup of ' + ExtractFileName(sDocFileName)); sBackup := FilePath(ExtractFileDir(sDocFileName), StripFileExtension(ExtractFileName(sDocFileName))) + '.' + tOptions.BackupExt; if tOptions.BackupFiles then begin CopyFile(PChar(sBackupFileName), PChar(sBackup), False); Document.SaveToFile(sBackupFileName); end; Document.SaveToFile(sDocFileName); bDocDirty := False; if tOptions.SaveBrowserRefresh then DocPreviewWithLastBrowser; if (Rover.SaveRefresh) and (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).UpdateRover; HideToolbarShit(False); if Assigned(MainForm.tpnlProjects) then tProject.DocumentSaved(sDocFileName); //MainForm.RefreshDocumentWeight; end else begin SaveAs; end; end; except end; end; function TfrmDoc.CheckSave: Word; { Function checks if document is dirty, if so asks to save changes. } { If yes, saves document. Return value one of [mrYes, mrNo, mrCancel], } { corresponding to users choice in dialog. } var wrdReturnValue: Word; sCaption: String; sFileName: String; begin wrdReturnValue := mrYes; if bDocDirty then begin if Length(sDocFileName) = 0 then sFileName := 'Untitled' else sFileName := sDocFileName; if bInternet then sCaption := 'Save changes to ' + ExtractFileName(InternetFileName) + '?' else sCaption := 'Save changes to ' + ExtractFileName(sFileName) + '?'; wrdReturnValue := MessageDlg(sCaption, mtConfirmation, [mbYes, mbNo, mbCancel], 0); if wrdReturnValue = mrYes then Save; end; Result := wrdReturnValue; end; function TfrmDoc.LoadDocumentServer(bFailedOnce : Boolean) : Boolean; var sRegFilename : String; OleSysError: EOleSysError; OleException: EOleException; begin result := True; try Document := CreateOLEObject('Sausage.HTMLTextDocument.2'); except on e: Exception do begin begin if e is EOleException then begin OleException := (e as EOleException); MessageDlg(OleException.Message, mtError, [mbOK], 0); end else if e is EOleSysError then begin OleSysError := (e as EOleSysError); if DWord(OleSysError.ErrorCode) = CO_E_CLASSSTRING then begin if bFailedOnce then MessageDlg('Invalid class string : The file "HTMLDocumentSvr2.dll" has not been registered correctly.', mtError, [mbOK], 0) else begin RegisterFiles; result := LoadDocumentServer(True); Application.ProcessMessages; Exit; end; end else if DWord(OleSysError.ErrorCode)= REGDB_E_CLASSNOTREG then begin if bFailedOnce then MessageDlg('Class not registered : The file "HTMLDocumentSvr2.dll" has not been registered correctly.', mtError, [mbOK], 0) else begin RegisterFiles; Application.ProcessMessages; result := LoadDocumentServer(True); Exit; end; end else if OleSysError.ErrorCode = ERROR_DLL_NOT_FOUND then begin MessageDlg('DLL not found : The file "HTMLDocumentSvr2.dll" has been registered but could not be loaded correctly.', mtError, [mbOK], 0); end else if OleSysError.ErrorCode = -2147023739 then begin MessageDlg('DLL not found : The file "HTMLDocumentSvr2.dll" has been registered but could not be loaded correctly.', mtError, [mbOK], 0); end else MessageDlg(OleSysError.Message, mtError, [mbOK], 0); end else MessageDlg(e.message, mtError, [mbOK], 0); end; Result := False; end; end; end; procedure TfrmDoc.FormCreate(Sender: TObject); var c: Integer; bContinue: Boolean; begin bContinue := True; bSetup := False; bActive := False; bFirstLoaded := True; iBookMarkWidth := (rtfDoc.BookmarkWidth * 4); c := Screen.Cursor; try Screen.Cursor := crHourglass; if rtfDoc <> nil then begin rtfDoc.SetBounds(0, 0, ClientWidth, (ClientHeight - panButtons.Height)); rtfDoc.HideSelection := False; end; bContinue := LoadDocumentServer(False); if bContinue then begin btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarCollapse'); Document.SetSyntaxManager(SyntaxManager); rtfDoc.Document := IDispatch(Document); //rtfDoc.SyntaxHighlight := True; rtfDoc.HighLightStyle := HTMLEDITVIEW_SYNTAX; rtfDoc.AutoConvert := False; if Not(tOptions.EditAutoIndent) then rtfDoc.AutoIndent := False; //UpdateTagColors; //LoadSyntaxColours(rtfDoc); //22/07/98 ClearCurrentElement; sDocFileName := ''; bInternet := False; iLastFind := 0; iReplaceCount := 0; iUntitledCount := 0; //rtfDoc.Clear; try SetDisplay; except end; //iLastRoverHeight := ctlRover.Height; rtfDoc.DisplayAll := tOptions.EditPara; rtfDoc.WordWrap := tOptions.EditWordWrap; rtfDoc.MouseSelectionEnable := True; rtfDoc.KeySelectionEnable := True; rtfDoc.CollapseBlockEnable := True; if tOptions.HTMLSyntax = True then rtfDoc.HighLightStyle := HTMLEDITVIEW_SYNTAX else begin If tOptions.HTMLTagColor = True then rtfDoc.HighLightStyle := HTMLEDITVIEW_TAGS else rtfDoc.HighLightStyle := HTMLEDITVIEW_NOTAGSYNTAX; //kin 190997 end; spdSyntax.Down := (rtfDoc.HighlightStyle = HTMLEDITVIEW_SYNTAX); spdTag.Down := (rtfDoc.HighLightStyle = HTMLEDITVIEW_TAGS); spdWordWrap.Down := rtfDoc.WordWrap; spdFields.Down := rtfDoc.DisplayAll; //spdGutter.Down := rtfDoc.ShowLineNumber; if not tOptions.OpenMaxDoc then begin WindowState := wsNormal; end; ResizeRoverToolbar(tOptions.EditorToolbarLarge); timAutoSave.Enabled := tOptions.AutoSave; timAutoSave.Interval := tOptions.AutoSaveTime * 60000; end; finally //ShowWindow(Handle, SW_HIDE); Screen.Cursor := c; bSetup := bContinue; end; end; procedure TfrmDoc.SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText, sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject); var iFoundPos: Integer; sMsgString: String; wrdCheck: Word; bCancel: Boolean; begin if bReplaceAll then dlgReplace.CloseDialog; bCancel := False; iLastFind := min_(iLastFind, Document.Length); iFoundPos := Document.FindString(iLastFind, Document.Length, sSearchText, True, bCase, bMatch); if iFoundPos > -1 then begin rtfDoc.SetSelection(iFoundPos, iFoundPos + Length(sSearchText)); rtfDoc.ScrollCaretToView; if not bFindOnly then begin wrdCheck := MessageDlg('Replace?', mtConfirmation, [mbYes, mbNo, mbCancel], 0); if wrdCheck = mrYes then begin //SelText := sReplaceText; //rtfDoc.ClearSelection; //Document.InsertText(sReplaceText, iFoundPos); SelText := sReplaceText; Inc(iReplaceCount); iLastfind := iFoundPos + Length(sReplaceText); end else if wrdCheck = mrNo then iLastFind := iFoundPos + Length(sSearchText) else if wrdCheck = mrCancel then begin bCancel := True; end; end else iLastfind := iFoundPos + Length(sSearchText); if (Not bFindOnly) and bReplaceAll and not(bCancel) then SearchAndReplace(bFindOnly, bReplaceAll, sSearchText, sReplaceText, bCase, bMatch, Sender); end else begin if (Sender is TFindDialog) then begin dlgFind.CloseDialog; sMsgString := 'Search string "' + sSearchText + '" not found.'; end; if (Sender is TReplaceDialog) then begin dlgReplace.CloseDialog; if iReplaceCount = 0 then sMsgString := 'Search string "' + sSearchText + '" not found.' else sMsgString := 'HotDog has made ' + IntToStr(iReplaceCount) + ' replacements.'; end; MessageDlg(sMsgString, mtInformation, [mbOk], 0); end; end; procedure TfrmDoc.dlgFindFind(Sender: TObject); begin SearchAndReplace(True, False, dlgFind.FindText, '', ((dlgFind.Options*[frWholeWord]) = [frWholeWord]), ((dlgFind.Options*[frMatchCase]) = [frMatchCase]), Sender); end; procedure TfrmDoc.DocReplace; begin {iLastfind := SelStart; iReplaceCount := 0; dlgReplace.Execute;} //FindReplace.Create(Self); FindReplace.Replace; end; procedure TfrmDoc.dlgReplaceFind(Sender: TObject); begin SearchAndReplace(True, False, dlgReplace.FindText, '', ((dlgReplace.Options*[frWholeWord]) = [frWholeWord]), ((dlgReplace.Options*[frMatchCase]) = [frMatchCase]), Sender); end; procedure TfrmDoc.dlgReplaceReplace(Sender: TObject); begin //SearchAndReplace(bFindOnly, bReplaceAll: Boolean; sSearchText, sReplaceText: String; bCase, bMatch: Boolean; Sender: Tobject); SearchAndReplace( False, //bFindOnly ((dlgReplace.Options*[frReplaceAll]) = [frReplaceAll]), //bReplaceAll dlgReplace.FindText, //sSearchText dlgReplace.ReplaceText, //sReplaceText ((dlgReplace.Options*[frWholeWord]) = [frWholeWord]), //bCase ((dlgReplace.Options*[frMatchCase]) = [frMatchCase]), //bMatch dlgReplace); end; procedure TfrmDoc.SelectAll; begin rtfDoc.SetSelection(0, Document.Length); end; procedure TfrmDoc.FormActivate(Sender: TObject); begin try if Assigned(MainForm.propSheet) then MainForm.propSheet.Selection := rtfDoc.Selection; if not(csDestroying in ComponentState) and not(bActive) and bSetup then begin //if Rover.DocumentForm <> Self then if MDI.ActiveMDIChild <> Self then timActivate.Enabled := True; end; MDI.SetActiveTab(MDI.ActiveMDIChild); except end; end; procedure TfrmDoc.timActivateTimer(Sender: TObject); begin timActivate.Enabled := False; GotFocus; if (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).PosRefreshRover(PreviewFilename, Text); end; procedure TfrmDoc.GotFocus; begin if not(csDestroying in ComponentState) and not(bCloseAll) and bSetup then begin bActive := True; MainForm.DirtyBird(True); HideToolbarShit(True); if not(MDI.TabChanging) then MDI.SetActiveTab(Self); //tProject.SetSnifferDoc(MDI.MDIChildIndex(Self)); SetFocus; bActive := False; if Assigned(MainForm.propSheet) then MainForm.propSheet.Selection := rtfDoc.Selection; if (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).UpdateRover; end; end; function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric; FontType: Integer; Data: Pointer): Integer; stdcall; begin THTMLEditView(Data).EditFont.Charset := LogFont.lfCharSet; //THTMLEditView(Data).EditFont.Height := LogFont.lfHeight; end; procedure TfrmDoc.SetDisplay; var DC: HDC; begin try rtfDoc.Enabled := False; try rtfDoc.EditFont.Name := tOptions.ViewFontName; rtfDoc.EditFont.Size := tOptions.ViewFontSize; except end; rtfDoc.FormatBackColor[0] := HTMLToColor(tOptions.ViewBackColour); rtfDoc.BackColor := rtfDoc.FormatBackColor[0]; rtfDoc.FormatTextColor[0] := HTMLToColor(tOptions.ViewTextColour); rtfDoc.AutoIndent := tOptions.EditAutoIndent; try DC := GetDC(0); EnumFonts(DC, PChar(rtfDoc.EditFont.Name), @EnumFontsProc, Pointer(rtfDoc)); ReleaseDC(0, DC); except end; rtfDoc.DragDropEdit := tOptions.EditDrag; rtfDoc.SmoothRefresh := tOptions.EditSmooth; {code Completion} rtfDoc.CodeCompletion := tOptions.CodeCompletionOn; rtfDoc.CodeCompletionMode := tOptions.CodeCompletionMode; try rtfDoc.CodeCompletionTimeDelay := tOptions.CodeCompletionDelay; except rtfDoc.CodeCompletionTimeDelay := 1000; end; if tOptions.ShowGutter then begin if tOptions.LineGutter then begin rtfDoc.IndentSize := iBookmarkWidth + (tOptions.LineGutterNumber * rtfDoc.GutterFontWidth); //+ rtfDoc.EditFont.Size //LINE_GUTTER_SIZE; rtfDoc.ShowLineNumber := True; end else begin //rtfDoc.IndentSize := NO_LINE_GUTTER_SIZE; //rtfDoc.IndentSize := rtfDoc.BookmarkWidth * rtfDoc.GutterFontWidth; rtfDoc.IndentSize := iBookmarkWidth + rtfDoc.GutterFontWidth; rtfDoc.ShowLineNumber := False; end; rtfDoc.LeftMarginVisible := True; spdGutter.Down := True; end else begin //rtfDoc.IndentSize := NO_GUTTER_SIZE; rtfDoc.IndentSize := rtfDoc.GutterFontWidth; rtfDoc.ShowLineNumber := False; rtfDoc.LeftMarginVisible := False; spdGutter.Down := False; end; rtfDoc.RightMarginVisible := tOptions.EditRightM; rtfDoc.RightMargin := tOptions.EditRightMSize; if rtfDoc.ColumnMax <> tOptions.EditColMax then rtfDoc.ColumnMax := tOptions.EditColMax; if rtfDoc.TabSize <> tOptions.EditTabSize then rtfDoc.TabSize := tOptions.EditTabSize; rtfDoc.AutoHint := tOptions.HTMLToolTips; rtfDoc.AutoDoc := tOptions.HTMLCoolTips; rtfDoc.AutoCloseBracket := tOptions.HTMLCloseTag; rtfDoc.GutterBitmapVisible := tOptions.ImageGutter; timAutoSave.Enabled := tOptions.AutoSave; timAutoSave.Interval := tOptions.AutoSaveTime * 60000; LoadSyntaxColours(rtfDoc); finally rtfDoc.Enabled := True; end; end; procedure TfrmDoc.DocInsert(Mode: modeInsert); begin case Mode of insImage: InsertImage; insLink: InsertLink(Mode); insEmail: InsertLink(Mode); insFTP: InsertLink(Mode); insNews: InsertLink(Mode); {insTarget: InsertTarget;} insLine: InsertLine; insTable: InsertTable; end; end; procedure TfrmDoc.InsertImage; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmImage, frmImage); finally Screen.Cursor := crDefault; end; try begin frmImage.sCurrentText := SelText; frmImage.sDocFileName := sDocFileName; frmImage.ShowModal; if Length(frmImage.sImgText) > 0 then AddText(frmImage.sImgText, '', False); end; finally frmImage.Free; end; end; function TfrmDoc.PreviewImage(sFilename : String) : String; var bResult : Boolean; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmImagelab, frmImagelab); finally Screen.Cursor := crDefault; end; try begin if sFilename <> '' then begin bResult := frmImageLab.ShowImage('SRC="' + FileToURL(sFilename) + '"', ''); end else begin bResult := frmImageLab.ShowImage(SelText,sDocFileName); end; if bResult then frmImagelab.ShowModal; //Get the Public image filename property, so that if a //drag drop called this dialog, it can get the new filename. Result := frmImagelab.sImageFilename; end; finally frmImagelab.Free; end; end; procedure TfrmDoc.DocComment; var tElement: Variant; iStart: Integer; bAutomatic : Boolean; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmComment, frmComment); finally Screen.Cursor := crDefault; end; try bAutomatic := False; tElement := Document.GetElementAt(SelStart, iStart); if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then frmComment.SetComment(Document.GetTextRange(iStart, iStart + tElement.Length + 1)) else frmComment.SetComment(SelText); if frmComment.GetComment = '' then frmComment.ShowModal else begin bAutomatic := True; if not frmComment.ParseComment then frmComment.CreateComment; end; if (frmComment.ModalResult = mrOK) or (bAutomatic) then begin if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then begin Document.ReplaceText(iStart, tElement.Length, frmComment.GetComment); //SelText := frmComment.GetComment; end else begin if Length(frmComment.GetComment) > 0 then AddText(frmComment.GetComment, '', False) else SelText := frmComment.GetComment; end; end; finally frmComment.Free; end; end; procedure TfrmDoc.DocEmbeded; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmEmbed, frmEmbed); finally Screen.Cursor := crDefault; end; try begin frmEmbed.sCurrentText := SelText; frmEmbed.ShowModal; if Length(frmEmbed.sCurrentText) > 0 then AddText(frmEmbed.sCurrentText, '', False); end; finally frmEmbed.Free; end; end; procedure TfrmDoc.DocDate; begin AddText(DateToStr(Date) + ' ' + TimeToStr(Time), '', False); end; procedure TfrmDoc.DocHotdogVersion; begin AddText('HotDog Professional 5', '', False); end; procedure TfrmDoc.DocCurrentFilename; begin if sDocFilename <> '' then AddText(sDocFileName, '', False) else AddText('Untitled', '', False); end; procedure TfrmDoc.DocWindowsVersion; begin if Win32Platform = VER_PLATFORM_WIN32s then AddText('Windows 3.1', '', False) else if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then AddText('Windows 95', '', False) else if Win32Platform = VER_PLATFORM_WIN32_NT then AddText('Windows NT', '', False); end; procedure TfrmDoc.DocUserName; begin tReg.CloseKey; tReg.RootKey := HKEY_LOCAL_MACHINE; if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then begin tReg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', False); if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then AddText(ReadRegString('RegisteredOwner'), '', False); end Else if Win32Platform = VER_PLATFORM_WIN32_NT then begin tReg.OpenKey('\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False); if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then AddText(ReadRegString('RegisteredOwner'), '', False); end; end; procedure TfrmDoc.DocCompanyName; begin tReg.CloseKey; tReg.RootKey := HKEY_LOCAL_MACHINE; if Win32Platform = VER_PLATFORM_WIN32_WINDOWS then begin tReg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion', False); if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then AddText(ReadRegString('RegisteredOrganization'), '', False); end Else if Win32Platform = VER_PLATFORM_WIN32_NT then begin tReg.OpenKey('\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False); if LowerCase(ReadRegString('RegisteredOwner')) <> 'keynotexist' then AddText(ReadRegString('RegisteredOrganization'), '', False); end; end; function TfrmDoc.GetPreviewFileName: String; var sReturn: String; begin if Length(sDocFileName) = 0 then sReturn := sPreviewFileName else //sReturn := ExtractFilePath(sDocFileName) + '~hd4preview.html'; sReturn := ExtractFilePath(sDocFileName) + '~hdprev.htm'; //- Sav 01-09-97 for Novell Server //Return Data Result := sReturn; end; procedure TfrmDoc.HideRover; var sFileName: String; //bResult: Boolean; begin sFileName := GetPreviewFileName; if Rover.Visible then Rover.ClearView; if FileExists(sFileName) then //bResult := DeleteFile(sFileName); end; function TfrmDoc.GetBodyTag : String; var iStart: Integer; iEnd: Integer; begin iStart := Find('<BODY', 0, False, False); if iStart > -1 Then begin iEnd := Find('>', iStart, False, False); if iEnd > -1 Then begin result := Document.GetTextRange(iStart, iEnd); end; end; end; procedure TfrmDoc.UpdateBodyTag(sBodyTag: String); var iStart: Integer; iEnd: Integer; begin //Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt; iStart := Find('<BODY', 0, False, False); if iStart > -1 Then begin iEnd := Find('>', iStart, False, False); if iEnd > -1 Then begin Document.ReplaceText(iStart, (iEnd - iStart) + 1, sBodyTag); if (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).UpdateRover; //UpdateRover; end; end; end; //procedure TfrmDoc.RecentFilesItemClick(Sender: TObject); {Hint} {var sFilename: string; tmpDoc: ^TfrmDoc;} //begin {Hint} {sFilename := (Sender as TMenuItem).Caption; sFileName := ChopAfter(sFilename, ' '); if MDI.MDIChildCount > 0 then begin if MDI.FindDocument(sFileName) = nil then begin //tmpDoc := TfrmDoc.Create(MainForm); tmpDoc := CreateDocWindow; tmpDoc.OpenDoc(sFileName); end else begin MDI.FindDocument(sFileName).BringToFront; MDI.FindDocument(sFileName).SetFocus; end; end else begin //tmpDoc := TfrmDoc.Create(MainForm); tmpDoc := CreateDocWindow; tmpDoc.OpenDoc(sFileName); end;} //end; {Hint} {procedure TfrmDoc.SetChildNum(I: Integer); begin //iChildNum := I; end;} {Hint} procedure TfrmDoc.DocCut; begin rtfDoc.Cut; HideToolbarShit(True); end; procedure TfrmDoc.DocCopy; begin rtfDoc.Copy; HideToolbarShit(True); end; procedure TfrmDoc.DocPaste; begin rtfDoc.Paste; HideToolbarShit(True); end; procedure TfrmDoc.DocPasteTable; begin SelText := GenerateTable(GetClipboardContents); end; procedure TfrmDoc.DocPasteLeftAligned; var sText : String; i : Integer; strLines : TStringList; begin strLines := TStringList.Create; try sText := GetClipboardContents; ParseLine(sText, #13#10, strLines); sText := ''; for i := 0 to strLines.Count -1 do sText := sText + TrimLeft(strLines.Strings[i]) + #13#10; sText := ReplaceString(sText, #13#10 + #13#10, '@SSPlaceHolder'); sText := ReplaceString(sText, #13#10, ' '); sText := ReplaceString(sText, '@SSPlaceHolder', #13#10+#13#10); finally strLines.Free; end; SelText := sText; end; procedure TfrmDoc.DocUndo; begin rtfDoc.Undo; //rtfDoc.UndoManager.Undo; //kin 190997 HideToolbarShit(True); end; procedure TfrmDoc.DocRedo; begin //rtfDoc.UndoManager.Redo; //kin 190997 rtfDoc.Redo; HideToolbarShit(True); end; procedure TfrmDoc.DocFind; begin {iLastfind := SelStart; dlgFind.Execute;} dlgFind := TFindDialog.Create(Self); dlgFind.Options := [frDown,frHideWholeWord,frHideUpDown]; dlgFind.OnFind := dlgFindFind; FindReplace.Find; dlgFind.Free; end; procedure TfrmDoc.DocFindF3; begin if SelLength > 0 then FindReplace.FindNextF3(SelStart + SelLength) else FindReplace.FindNextF3(SelStart); end; procedure TfrmDoc.InsertList; var sEnd: String; iPos: Integer; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmDocList, frmDocList); finally Screen.Cursor := crDefault; end; if tCurrentElement.iType <> HTMLSYNTAXELEMENT_INVALID then begin if tCurrentElement.sTagName = 'Bulleted List' then sEnd := '</ul>' else if tCurrentElement.sTagName = 'Numbered List' then sEnd := '</ol>' else if tCurrentElement.sTagName = 'Definition List' then sEnd := '</dl>'; if sEnd <> '' then begin iPos := Document.FindString(tCurrentElement.iStart, Document.Length - 1, sEnd, True, False, False); if iPos > -1 then begin rtfDoc.SetSelection(tCurrentElement.iStart, iPos + Length(sEnd)); frmDocList.sTag := Document.GetTextRange(tCurrentElement.iStart, iPos + Length(sEnd)); end; end; end else if SelLength > 0 then begin frmDocList.sTag := SelText; end; frmDocList.ShowModal; if Length(frmDocList.sList) > 0 then AddText(frmDocList.sList, '', False); ClearCurrentElement; end; procedure TfrmDoc.DocList; begin try Screen.Cursor := crhourglass; Application.CreateForm(TfrmDocList, frmDocList); finally Screen.Cursor := crDefault end; if SelLength > 0 then frmDocList.sTag := SelText; frmDocList.ShowModal; if Length(frmDocList.sList) > 0 then AddText(frmDocList.sList, '', False); end; procedure TfrmDoc.DocDefList; begin Application.CreateForm(TfrmDefList, frmDefList); frmDefList.sTag := SelText; ModalResult := frmDefList.ShowModal; if ModalResult = mrOk then SelText := frmDefList.sTag; end; (* procedure TfrmDoc.BullList; {var sEnd: String; iPos: Integer;} begin Application.CreateForm(TfrmDocList, frmDocList); if SelLength > 0 then begin frmDocList.sTag := SelText; end; frmDocList.ListStyle := LIST_BULLET; frmDocList.ShowModal; if Length(frmDocList.sList) > 0 then AddText(frmDocList.sList, '', False); end; procedure TfrmDoc.NumList; {var sEnd: String; iPos: Integer;} begin Application.CreateForm(TfrmDocList, frmDocList); if SelLength > 0 then begin frmDocList.sTag := SelText; end; frmDocList.ListStyle := LIST_NUMBERED; frmDocList.ShowModal; if Length(frmDocList.sList) > 0 then AddText(frmDocList.sList, '', False); end; *) procedure TfrmDoc.DocFont(bFromRightClick : Boolean); //returns false if the font dialog is cancelled var tElement: Variant; //iTextStart: Integer; //iTextEnd: Integer; iNext, iPos, iStart: Integer; sCurrent: String; sTagText: String; bGalvies: Boolean; sBegin, sEnd: String; //beginning and end of Font tag, inc. <b> </b> etc begin //We dont want to run this code all the time, because tCurrentElement will be out of sync if bFromRightClick then begin if tCurrentElement.iType <> HTMLSYNTAXELEMENT_INVALID then begin sEnd := '</font>'; iPos := Document.FindString(tCurrentElement.iStart, Document.Length - 1, sEnd, True, False, False); if iPos > -1 then begin //Find text iNext := tCurrentElement.iStart; repeat tElement := Document.GetElementAt(iNext, iStart); iNext := iStart + tElement.Length; until tElement.Type = HTMLSYNTAXELEMENT_TEXT; //iTextStart := iStart; repeat tElement := Document.GetElementAt(iNext, iStart); iNext := iStart + tElement.Length; until tElement.Type = HTMLSYNTAXELEMENT_TAG; //iTextEnd := iStart; //sTagText := Document.GetTextRange(iTextStart, iTextEnd); rtfDoc.SetSelection(tCurrentElement.iStart, iPos + Length(sEnd)); sCurrent := Document.GetTextRange(tCurrentElement.iStart, iPos + Length(sEnd)); //bGalvies := False; end else begin rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength); sCurrent := Document.GetTextRange(tCurrentElement.iStart, tCurrentElement.iLength); //bGalvies := True; end; end; end; //else} //begin bGalvies := False; //Check if current <FONT> </FONT> tags are selected sCurrent := GetTag(SelText, '<font', '</font>'); if Length(sCurrent) = 0 then begin //see if just <FONT> tag is selected sCurrent := GetTag(SelText, '<font', '>'); if Length(sCurrent) > 0 then bGalvies := True; end; //end; Application.CreateForm(TfrmFontDlg, frmFontDlg); try if Length(sCurrent) > 0 then begin frmFontDlg.HTMLFont := ParseForFont(sCurrent); frmFontDlg.sTagGuts := GetTagGuts(sCurrent, '>', '</font>'); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<strong>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</strong>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<b>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</b>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<em>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</em>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<i>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</i>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<u>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</u>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<sup>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</sup>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'<sub>', ''); frmFontDlg.sTagGuts := ReplaceString(frmFontDlg.sTagGuts,'</sub>', ''); end else sTagText := SelText; frmFontDlg.ShowModal; if frmFontDlg.ModalResult = mrOK then begin BuildFontTag(frmFontDlg.HTMLFont, sBegin, sEnd); if bGalvies then AddText(sBegin, sEnd, False) else begin if sTagText = frmFontDlg.sTagGuts then AddText(sBegin + sTagText, sEnd, False) else AddText(sBegin + sTagText + frmFontDlg.sTagGuts, sEnd, False); end; end; ClearCurrentElement; finally frmFontDlg.Free; end; end; function TfrmDoc.ParseForFont(sText: String): THTMLFont; var tmpFont: THTMLFont; begin tmpFont.Style := []; //tmpFont := TFont.Create; tmpFont.Name := GetAttribute(sText, 'Face'); tmpFont.Size := GetAttribute(sText, 'Size'); tmpFont.Color := HTMLToColor(GetAttribute(sText, 'Color')); //(fsBold, fsItalic, fsUnderline, fsSuperscript, fsSubscript, fsBlink); if (Length(GetTag(LowerCase(sText), '<b>', '</b>'))) or (Length(GetTag(LowerCase(sText), '<strong>', '</strong>'))) > 0 then tmpFont.Style := tmpFont.Style + [hfsBold]; if (Length(GetTag(LowerCase(sText), '<i>', '</i>'))) or (Length(GetTag(LowerCase(sText), '<em>', '</em>'))) > 0 then tmpFont.Style := tmpFont.Style + [hfsItalic]; if Length(GetTag(LowerCase(sText), '<u>', '</u>')) > 0 then tmpFont.Style := tmpFont.Style + [hfsUnderline]; if Length(GetTag(LowerCase(sText), '<sup>', '</sup>')) > 0 then tmpFont.Style := tmpFont.Style + [hfsSuperscript]; if Length(GetTag(LowerCase(sText), '<sub>', '</sub>')) > 0 then tmpFont.Style := tmpFont.Style + [hfsSubscript]; if Length(GetTag(LowerCase(sText), '<blink>', '</blink>')) > 0 then tmpFont.Style := tmpFont.Style + [hfsBlink]; //Return Result Result := tmpFont; end; procedure TfrmDoc.AddText(sText, sEnd: String; bSkipRemoval: Boolean); var bBoth: Boolean; lWhere: LongInt; bKeepHighlight: Boolean; lCurrSelLength: LongInt; lCurrSelText: String; //iAddCR: Integer; bRemoval: Boolean; sNewText: String; begin bKeepHighLight := False; bBoth := False; //iAddCR := 0; bRemoval := False; lWhere := selStart; lCurrSelLength := selLength; lCurrSelText := SelText; if lCurrSelLength > 0 Then bKeepHighlight := True; if (Length(sText) > 0) And (Length(sEnd) > 0) And (lCurrSelLength = 0) Then bBoth := True; //if end tag exists and nothing is highlighted, //set cursor between the tags sNewText := SelText; while Right(sNewText, 2) = #13#10 do begin sNewText := ChopString(sNewText, 2); //Inc(iAddCR); end; if not(bSkipRemoval) then if RemoveExistingTags(sText, sEnd) Then bRemoval := True; //Add the Text sNewText := sText; If Not bRemoval Then sNewText := sNewText + sEnd; {while iAddCr > 0 do begin sNewText := sNewText + #13#10; Dec(iAddCr); end;} SelText := sNewText; //LockWindowUpdate(MainForm.Handle); If bKeepHighlight Then begin rtfDoc.SetSelection(lWhere, lWhere + Length(sNewText)); end else begin If bBoth Then SetCursorPos(lWhere + Length(sText)) else SetCursorPos(lWhere + Length(sNewText)); end; if (Rover.TagRefresh) and (MainForm is TfrmMainRover) then (MainForm as TfrmMainRover).PosRefreshRover(PreviewFileName, Text); //LockWindowUpdate(0); end; procedure TfrmDoc.DocBold; begin if tOptions.HTMLStrongTag then AddText(tOptions.TagCase('<STRONG>') + SelText, tOptions.TagCase('</STRONG>'), False) else AddText(tOptions.TagCase('<B>') + SelText, tOptions.TagCase('</B>'), False); end; procedure TfrmDoc.DocItalic; begin if tOptions.HTMLEMTag then AddText(tOptions.TagCase('<EM>') + SelText, tOptions.TagCase('</EM>'), False) else AddText(tOptions.TagCase('<I>') + SelText, tOptions.TagCase('</I>'), False); end; procedure TfrmDoc.DocUnderline; begin AddText(tOptions.TagCase('<U>') + SelText, tOptions.TagCase('</U>'), False); end; procedure TfrmDoc.DocCenter; begin AddText(tOptions.TagCase('<CENTER>') + SelText, tOptions.TagCase('</CENTER>'), False); end; procedure TfrmDoc.DocPara; begin if tOptions.ParaContainer then AddText(tOptions.TagCase('<P>') + SelText, tOptions.TagCase('</P>'), False) else AddToSelText(tOptions.TagCase('<P>')); end; procedure TfrmDoc.DocBreak; var sText : String; begin sText := SelText; SelText := ''; if sText = '' then InsertText('<BR>', SelStart) else begin if Pos(#13#10, sText) > 0 then begin //SelText := ReplaceString(SelText, #13#10, '<BR>'+ #13#10); sText := ReplaceString(sText, #13#10, '<BR>'+ #13#10) + '<BR>'; InsertText(sText, SelStart); end //the text that is selected is going to be deleted by the return keypress, //(even though key is set to 0) so add it back. else InsertText(sText + '<BR>', SelStart); // SelText := SelText + '<BR>'; end; end; procedure TfrmDoc.DocNOBR; begin AddToSelText(tOptions.TagCase(' ')); end; procedure TfrmDoc.AddToSelText(sText: String); var iWhere: Integer; iCurrSelLength: Integer; begin iWhere := selStart; iCurrSelLength := selLength; SelText := SelText + sText; if iCurrSelLength > 0 then begin SetSelection(iWhere, iCurrSelLength + Length(sText)); end else SetCursorPos(iWhere + Length(sText)); end; procedure TfrmDoc.DocPrintSetup; begin if Printer.Printers.Count = 0 then MessageDlg('There are currently no installed printers.' + 'You will need to install a Windows printer to print the document.', mtInformation, [mbOK], 0) else rtfDoc.PageSetup; end; procedure TfrmDoc.DocPrint; //var -sav //iPixPerInch, iTwips: Integer; //rtfTemp: TRichEdit; -sav //tr: TRect; //DC: hDC; begin if Printer.Printers.Count = 0 then MessageDlg('There are currently no installed printers.' + 'You will need to install a Windows printer to print the document.', mtError, [mbOK], 0) else rtfdoc.Print(sDocFilename); (*else if dlgPrint.Execute then begin rtfTemp := TRichEdit.Create(Self); try Screen.Cursor := crHourglass; rtfTemp.Visible := False; rtfTemp.Parent := Self; rtfTemp.Width := rtfDoc.Width; rtfTemp.Height := rtfDoc.Height; rtfTemp.Text := Document.Text; rtfTemp.WordWrap := rtfDoc.WordWrap; rtfTemp.Font.Name := rtfDoc.EditFont.Name; rtfTemp.Font.Size := rtfDoc.EditFont.Size; {DC := GetDC(rtfDoc.HWnd); iPixPerInch := GetDeviceCaps(DC, LOGPIXELSX); ReleaseDC(rtfDoc.HWnd, DC); iTwips := (rtfDoc.ColumnMax / iPixPerInch) * 1440; tr := rtfTemp.PageRect; tr.Right := iTwips; rtfTemp.PageRect := tr;} Status('Printing document...'); rtfTemp.Print(sDocFileName); finally Status(''); Screen.Cursor := crDefault; rtfTemp.Free; end; end;*) end; procedure TfrmDoc.KillTmpFile; begin if FileExists(sBackupFileName) then DeleteFile(sBackupFileName); end; {function TfrmDoc.CleanSaveAsName(sName, sDefExt: String): String; var //Damned common dialog...appends default extension if it is different iFirstDot: Integer; iExt: Integer; begin iExt := Pos('.' + sDefExt, sName); iFirstDot := Pos('.', sName); If (iExt > 0) And (iFirstDot > 0) Then If iExt <> iFirstDot Then //DOH ! two extensions - clean out the default subReplaceString(sName, '.' + sDefExt, '', True); Result := sName; end;} {Hint} procedure TfrmDoc.BuildFontTag(tmpFont: THTMLFont; var sBegin, sEnd: String); begin sBegin := tOptions.TagCase('<FONT'); if Length(tmpFont.Name) > 0 then sBegin := sBegin + tOptions.TagCase(' FACE="') + tmpFont.Name + '"'; if tmpFont.Size <> '' then sBegin := sBegin + tOptions.TagCase(' SIZE="') + tmpFont.Size + '"'; if tmpFont.Color > 0 then sBegin := sBegin + tOptions.TagCase(' COLOR="#') + GetHexColourStr(tmpFont.Color) + '"'; sBegin := sBegin + '>'; sEnd := tOptions.TagCase('</FONT>'); if hfsBold in tmpFont.Style then begin if tOptions.HTMLStrongTag then begin sBegin := sBegin + tOptions.TagCase('<STRONG>'); sEnd := tOptions.TagCase('</STRONG>') + sEnd; end else begin sBegin := sBegin + tOptions.TagCase('<B>'); sEnd := tOptions.TagCase('</B>') + sEnd; end; end; if hfsItalic in tmpFont.Style then begin if tOptions.HTMLEMTag then begin sBegin := sBegin + tOptions.TagCase('<EM>'); sEnd := tOptions.TagCase('</EM>') + sEnd; end else begin sBegin := sBegin + tOptions.TagCase('<I>'); sEnd := tOptions.TagCase('</I>') + sEnd; end; end; if hfsUnderline in tmpFont.Style then begin sBegin := sBegin + tOptions.TagCase('<U>'); sEnd := tOptions.TagCase('</U>') + sEnd; end; if hfsSuperscript in tmpFont.Style then begin sBegin := sBegin + tOptions.TagCase('<SUP>'); sEnd := tOptions.TagCase('</SUP>') + sEnd; end; if hfsSubscript in tmpFont.Style then begin sBegin := sBegin + tOptions.TagCase('<SUB>'); sEnd := tOptions.TagCase('</SUB>') + sEnd; end; if hfsBlink in tmpFont.Style then begin sBegin := sBegin + tOptions.TagCase('<BLINK>'); sEnd := tOptions.TagCase('</BLINK>') + sEnd; end; end; (* procedure TfrmDoc.InsertLink(Mode: modeInsert); var sCurrent: String; sTagText: String; bGalvies: Boolean; begin bGalvies := False; //Check if current <A HREF> </A> tags are selected sCurrent := GetTag(LowerCase(SelText), '<a href', '</a>'); if Length(sCurrent) = 0 then begin //see if just <A HREF> tag is selected sCurrent := GetTag(LowerCase(SelText), '<a href', '>'); if Length(sCurrent) > 0 then bGalvies := True; end; if Length(sCurrent) > 0 then begin if Not(bGalvies) then sTagText := Between(LowerCase(sCurrent), '>', '</a>'); end else sTagText := SelText; Application.CreateForm(TfrmLink, frmLink); frmLink.sCurrent := sCurrent; frmLink.sText := sTagText; frmLink.Mode := Mode; frmLink.sFileName := sDocFileName; frmLink.ShowModal; if frmLink.ModalResult = mrOK then begin //AddText(sText, sEnd, bSkipRemoval); if bGalvies then AddText(frmLink.sLink + frmLink.sText, '', True) else AddText(frmLink.sLink + frmLink.sText, '</A>', True); end; frmLink.Release; end; *) procedure TfrmDoc.InsertLink(Mode : modeInsert); var sCurrent: String; sTagText: String; bGalvies: Boolean; begin bGalvies := False; //Check if current <A HREF> </A> tags are selected sCurrent := GetTag(SelText, '<a href', '</a>'); (*mg261197 removed lowercase *) if Length(sCurrent) = 0 then begin //see if just <A HREF> tag is selected sCurrent := GetTag(SelText, '<a href', '>'); (*mg261197 removed lowercase *) if Length(sCurrent) > 0 then bGalvies := True; end; if Length(sCurrent) > 0 then begin if Not(bGalvies) then sTagText := Between(sCurrent, '>', '</a>'); end else sTagText := SelText; Screen.Cursor := crhourglass; Application.CreateForm(TfrmLink, frmLink); Screen.Cursor := crDefault; try frmLink.sCurrent := sCurrent; frmLink.sText := sTagText; frmLink.Mode := Mode; frmLink.sFileName := sDocFileName; frmLink.ShowModal; if frmLink.ModalResult = mrOK then begin //AddText(sText, sEnd, bSkipRemoval); {if bGalvies then AddText(frmLink.sLink + frmLink.sText, '', False) else AddText(frmLink.sLink + frmLink.sText, tOptions.TagCase('</A>'), False); } AddText(frmLink.sLink, '', False); end; finally frmLink.Release; end; end; procedure TfrmDoc.DocBigFirst; var sText: String; sTag: String; begin sTag := tOptions.TagCase('<FONT SIZE="+1">'); sText := SelText; if Length(SelText) > 0 then begin sTag := sTag + sText[1]; sText := Copy(SelText, 2, SelLength); end; SelText := sTag + tOptions.TagCase('</FONT>') + sText; //AddText(sTag + sText, '</FONT>', False); end; procedure TfrmDoc.Center1Click(Sender: TObject); begin DocCenter; end; procedure TfrmDoc.InsertLine; var sCurrent: String; begin //Check if current <HR> tags are selected //sCurrent := GetTag(LowerCase(SelText), '<hr', '>'); sCurrent := SelText; try Screen.Cursor := crHourglass; Application.CreateForm(TfrmInsRule, frmInsRule); finally Screen.Cursor := crDefault; end; frmInsRule.sSelText := sCurrent; frmInsRule.ShowModal; if frmInsRule.ModalResult = mrOK then begin AddText(frmInsRule.sLineTag, '', False); end; end; procedure TfrmDoc.DocPreview; var sBrowser: String; sList: TStringList; begin //Find Browser if tReg.OpenTo(INI_OPTIONS_BROWSERS, False) then begin sList := TStringList.Create; try begin tReg.GetValueNames(sList); if sList.Count > 0 then sBrowser := tReg.ReadString(sList.Strings[0]); end finally sList.Free; end; end; //Preview //Document.SaveToFile(GetPreviewFileName); WriteWholeFile(GetPreviewFileName, Document.Text); mFilePreview(sBrowser, GetPreviewFileName); end; function TfrmDoc.DocPreviewWithBrowser(sBrowser: String) : boolean; begin //Document.SaveToFile(GetPreviewFileName); WriteWholeFile(GetPreviewFileName, Document.Text); Result := mFilePreview(sBrowser, GetPreviewFileName); end; function TfrmDoc.DocPreviewWithLastBrowser : Boolean; // Sav 01-09-97 //When F9 is pressed, preview using the last browser used. var slBrowsers : TStringlist; // i : Integer; begin result := False; try If (Trim(tOptions.LastBrowserUsed) <> '') and (FileExists(tOptions.LastBrowserUsed)) Then begin WriteWholeFile(GetPreviewFileName, Document.Text); mFilePreview(tOptions.LastBrowserUsed, GetPreviewFileName); end else begin //if there is no previous browser used, then grab the first one in the registry list. if tReg.OpenTo(INI_OPTIONS_BROWSERS, False) then begin slBrowsers := TStringList.Create; try tReg.GetValueNames(slBrowsers); if slBrowsers.Count > 0 then result := DocPreviewWithBrowser(tReg.ReadString(slBrowsers.Strings[0])); finally slBrowsers.Free; end; end; end; except end; end; function TfrmDoc.SelStart: LongInt; var lStart, lEnd: Integer; begin if rtfDoc <> nil then begin lStart := rtfDoc.SelectionStart; lEnd := rtfDoc.SelectionEnd; Result := min_(lStart, lEnd); end else Result := 0; end; function TfrmDoc.SelEnd: LongInt; var lStart, lEnd: Integer; begin if rtfDoc <> nil then begin lStart := rtfDoc.SelectionStart; lEnd := rtfDoc.SelectionEnd; Result := min_(max_(lStart, lEnd), Document.Length - 1); end else Result := 0; end; function TfrmDoc.GetWordAtPos(iPos: Integer; var iStart, iEnd: Integer): String; var iFirst, iLast: Integer; begin rtfDoc.GetWordPosAtPos(iPos, iFirst, iLast); iStart := min_(iFirst, iLast); iEnd := max_(iFirst, iLast); iEnd := min_(iEnd, Document.Length); Result := Document.GetTextRange(iStart, iEnd); end; function TfrmDoc.GetNextTextBlock(var iStart: Integer): String; var sResult: String; iCount: Integer; tElement: Variant; begin Result := ''; iCount := iStart; while iCount < Document.Length - 1 do begin try tElement := Document.GetElementAt(iCount, iStart); if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then iCount := iCount + tElement.Length //- 1 else begin //find in list and replace with tag //if (iStart + tElement.Length {+ 1}) < Document.Length then sResult := Document.GetTextRange(iStart, iStart + tElement.Length); //else // sResult := Document.GetTextRange(iStart, Document.Length); if Length(Trim(sResult)) > 0 then begin Result := sResult; iCount := Document.Length; end else iCount := iCount + tElement.Length; //- 1; end; except end; end; end; function TfrmDoc.GetNextTag(var iStart: Integer): String; var sResult: String; iCount: Integer; tElement: Variant; begin Result := ''; iCount := iStart; while iCount < Document.Length - 1 do begin try tElement := Document.GetElementAt(iCount, iStart); if tElement.Type <> HTMLSYNTAXELEMENT_TAG then //iCount := iCount + tElement.Length - 1 iCount := iCount + tElement.Length else begin //find in list and replace with tag if (iStart + tElement.Length + 1) < Document.Length then sResult := Document.GetTextRange(iStart, iStart + tElement.Length) else sResult := Document.GetTextRange(iStart, Document.Length); if Length(Trim(sResult)) > 0 then begin Result := sResult; iCount := Document.Length; end else iCount := iCount + tElement.Length - 1; end; except end; end; end; function TfrmDoc.SelLength: LongInt; var lStart, lEnd: Integer; begin if bSetup then begin if rtfDoc <> nil then begin lStart := rtfDoc.SelectionStart; lEnd := rtfDoc.SelectionEnd; Result := max_(lStart, lEnd) - min_(lStart, lEnd); end else Result := 0; end else Result := 0; end; function TfrmDoc.Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt; var sType: TSearchTypes; begin sType := []; //forward, case sensitive, regular expression Result := -1; try FindReplace.rtfFind.Text := Document.Text; if bCase then sType := sType + [stMatchCase]; if bWholeWord then sType := sType + [stWholeWord]; Result := FindReplace.rtfFind.FindText(sString, iStart, Document.Length - iStart, sType); except //nada end; end; function TfrmDoc.GetSelText: String; begin try Result := Document.GetTextRange(SelStart, SelEnd); except end; end; procedure TfrmDoc.SetSelText(sText: String); var iStart: Integer; begin iStart := SelStart; Document.ReplaceText(iStart, SelLength, sText); rtfDoc.SetSelection(iStart, iStart + Length(sText)); rtfDoc.ScrollCaretToView; end; function TfrmDoc.GetDocText: String; begin Result := Document.Text; end; procedure TfrmDoc.SetDocText(sText: String); begin Document.ReplaceText(0, Document.Length, sText); end; function TfrmDoc.GetDocHead: String; var iStart, iEnd: Integer; begin if FindDocHead(iStart, iEnd) then begin iStart := iStart + Length('<HEAD>'); Result := Document.GetTextRange(iStart, iEnd) end else Result := ''; end; procedure TfrmDoc.SetDocHead(sText: String); var iStart, iEnd: Integer; begin if Length(sText) > 0 then if FindDocHead(iStart, iEnd) then begin iEnd := iEnd + Length('</HEAD>'); Document.ReplaceText(iStart, (iEnd - iStart), sText); end; end; function TfrmDoc.FindDocHead(var iStart, iEnd: Integer): Boolean; begin iStart := -1; iEnd := -1; iStart := Document.FindString(0, Document.Length - 1, '<HEAD>', True, False, False); if iStart > -1 then begin iEnd := Document.FindString(iStart, Document.Length - 1, '</HEAD>', True, False, False); end; Result := (iStart > -1) and (iEnd > -1); end; function TfrmDoc.GetTextRange(iStart, iLength: Integer): String; begin Result := ''; if (min_(iStart, iLength) > 0) and (max_(iStart, iLength) < Document.Length - 1) then Result := Document.GetTextRange(iStart, iLength); end; procedure TfrmDoc.InsertText(sText: String; iPos: LongInt); begin Document.InsertText(sText, iPos); end; procedure TfrmDoc.rtfDocDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); {var iStart: Integer;} begin if (Source is TPTShellList) then Accept := True else if (Source = MainForm.ptlstNSFaves) then Accept := True else if (Source = MainForm.ptlstIEFaves) then Accept := True else if (Source = MainForm.tvProjects) then Accept := tOptions.CanEdit(ExtractFileExt((MainForm.tvProjects.Selected as TTreeNode).Text)) else if (Source = MainForm.lvInternetFiles) then Accept := tOptions.CanEdit(ExtractFileExt(MainForm.lvInternetFiles.Selected.Caption)) else if (Source = MainForm.lvWSFiles) then Accept := True; end; procedure TfrmDoc.QuickLink(sFileName: String); var sText: String; begin sText := tOptions.TagCase('<A HREF="'); sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)); if SelLength > 0 then sText := sText + '">' + SelText + tOptions.TagCase('</A>') else sText := sText + '">' + ExtractFileName(sFileName) + tOptions.TagCase('</A>'); AddText(sText, '', True); end; procedure TfrmDoc.QuickImage(sFileName: String); var pmimgPreview: TPMultiImage; sText: String; c: TCursor; begin c := Screen.Cursor; Screen.Cursor := crHourglass; pmimgPreview := TPMultiImage.Create(Self); pmimgPreview.Visible := False; pmimgPreview.Parent := Self; pmimgPreview.Stretch := True; try pmimgPreview.ImageName := sFileName; if SelLength = 0 then begin sText := tOptions.TagCase('<IMG SRC="') + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)) + '"'; try sText := sText + ' WIDTH="' + IntToStr(pmimgPreview.bWidth) + '"'; except end; try sText := sText + ' HEIGHT="' + IntToStr(pmimgPreview.bHeight) + '"'; except end; try sText := sText + ' BORDER="0"'; except end; try sText := sText + ' ALT="' + ExtractFileName(sFileName) + ' - ' + IntToStr(pmimgPreview.bSize) + ' Bytes' + '"'; except end; sText := sText + '>' + GetSelText; end else begin sText := tOptions.TagCase('<A HREF="'); sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)) + '"'; //sText := sText + '">' + SelText + '</A>'; //sText := sText + ' HEIGHT="' + IntToStr(pmimgPreview.bHeight) + '"'; //sText := sText + ' WIDTH="' + IntToStr(pmimgPreview.bWidth) + '"'; //sText := sText + ' ALT="' + ExtractFileName(sFileName) + '"'; sText := sText + '>' + SelText + tOptions.TagCase('</A>'); end; AddText(sText, '', True); finally pmimgPreview.Free; Screen.Cursor := c; end; end; procedure TfrmDoc.rtfDocSelectionChanged(Sender: TObject; nStart, nEnd: Integer); var iCol, iRow: Integer; begin if bSetup then begin //iLastfind := SelStart; HideToolbarShit(True); rtfDoc.FindCoordinateFromPosition(nStart, iCol, iRow); SetCoords(iCol, iRow); FindReplace.SelChanged(nStart); //MainForm.propSheet.Position := nStart; end; end; procedure TfrmDoc.rtfDocDragDrop(Sender, Source: TObject; X, Y: Integer); const MOUSEEVENTF_LEFTDOWN = $2; //left button down MOUSEEVENTF_ABSOLUTE = $8000; //absolute move MOUSEEVENTF_LEFTUP = $4; //left button up var ItemData: TPTShListData; sLink: String; //Info: TShellLinkInfo; tRegIni: TIniFile; iStart : Integer; iSelStart, iSelEnd : Integer; //sPathname : String; sImage : String; rectSelection : TGridRect; sDesc: TPTShListData; begin if SelLength = 0 then begin iStart := rtfDoc.FindPositionFromPoint(X, Y); rtfDoc.SetSelection(iStart, iStart); end; if (Source = MainForm.ptList) then begin ItemData := (Source as TPTShellList).SelectedItem; if tOptions.IsImage(ItemData.PathName) then begin QuickImage(ItemData.PathName); end else //if tOptions.CanEdit(ExtractFileExt(ItemData.PathName)) then begin if tOptions.IsPreviewableImage(ItemData.PathName) then begin ModalResult := MessageDlg(ExtractFileExt(ItemData.PathName) + ' files cannot be inserted into Hotdog. Do you wish to ' + 'convert this image to another file format? Selecting No will insert a link to this file.', mtConfirmation, [mbYes, mbNo, mbCancel],0); if ModalResult = mrYes then begin sImage := PreviewImage(ItemData.PathName); if tOptions.IsImage(sImage) then QuickImage(sImage); end else if ModalResult = mrNo then QuickLink(ItemData.PathName); end else QuickLink(ItemData.PathName); end; end else if (Source = MainForm.lvWSFiles) and (MainForm.lvWSFiles.Selected <> Nil) then begin sDesc := TPTShListData(MainForm.lvWSFiles.Selected.Data); if sDesc <> nil then begin if tOptions.IsImage(sDesc.PathName) then QuickImage(sDesc.PathName) else QuickLink(sDesc.PathName); end; end //QuickLink((MainForm.lvProjects.Selected as TTreeNode).Text) else if (Source = MainForm.lvInternetFiles) and (MainForm.lvInternetFiles.Selected <> Nil) then QuickLink(MainForm.lvInternetFiles.Selected.Caption) else if (Source = MainForm.ptlstNSFaves) then begin //GetShellLinkInfo(MainForm.ptlstNSFaves.SelectedItem.Pathname, Info); sLink := ReadWholeFile(MainForm.ptlstNSFaves.SelectedItem.Pathname); DocFaveLink(Between(sLink, #13#10, #13#10), Copy(sLink, 0, Pos(#13#10, sLink) -1)); end else if (Source = MainForm.ptlstIEFaves) then begin tRegIni := TIniFile.Create(MainForm.ptlstIEFaves.SelectedItem.Pathname); try begin { sample [InternetShortcut] URL=http://www.bitch.com/ } sURL := tRegIni.ReadString('InternetShortcut', 'URL', ''); if sURL <> '' then DocFaveLink(sURL, MainForm.ptlstIEFaves.SelectedItem.Filename); end finally tRegIni.Free; end; //GetShellLinkInfo(MainForm.ptlstIEFaves.SelectedItem.Pathname, Info); //sURL := Info.Description; //DocFaveLink(sURL, MainForm.ptlstIEFaves.SelectedItem.Filename); end else if (Source = MainForm.treeMacro) then begin MainForm.treeMacroDblClick(Self); end else if (Source = MainForm.treeTags) then begin sURL := CreateTagsDropText(Source, SelText); AddText(sURL, '', True); end else if (Source = MainForm.lvExtChar) then begin if Pos('>', MainForm.lvExtChar.ItemFocused.SubItems[0]) = 0 then AddText(MainForm.lvExtChar.ItemFocused.SubItems[0] + ';', '', True) else AddText(MainForm.lvExtChar.ItemFocused.SubItems[0], '', True); end //ThumbNailButton made Modal so that other dialogs won't hide behind it. {else if ((Source as TControl).parent.classname = 'TThumbNailButton') then begin sPathName := ((Source as TControl).parent as TThumbNailButton).PathName; if tOptions.IsImage(sPathName) then QuickImage(((Source as TControl).parent as TThumbNailButton).PathName) else begin if MessageDlg(ExtractFileExt(sPathName) + ' files cannot be inserted into Hotdog. Do you wish to ' + 'convert this image to another file format?', mtConfirmation, [mbYes, mbNo],0) = mrYes then PreviewImage(sPathName); end; end} else if (Source = MainForm.strClipboard) then begin rectSelection := MainForm.strClipboard.Selection; if MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] <> nil then //SelText := (MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] as TClipboardString).sItem; AddText((MainForm.strClipboard.Objects[rectSelection.TopLeft.X, rectSelection.TopLeft.Y] as TClipboardString).sItem, '', True); end //Should leave this last because it is simply testing for TPanel else if (Source is TPanel) then begin if (Source as TPanel).Parent = MainForm.panColours then AddText((Source as TPanel).Hint, '', True); end; MainForm.SetFocus; SendMessage(Handle, WM_SETFOCUS, 0,0); rtfDoc.ScrollCaretToView; end; procedure TfrmDoc.DocFaveLink(sFileName, sDesc: String); var sText: String; begin sText := tOptions.TagCase('<A HREF="'); sText := sText + FileToURL(AbsoluteToRelative(sDocFileName, sFileName)); if SelLength > 0 then sText := sText + '">' + SelText + tOptions.TagCase('</A>') else sText := sText + '">' + Trim(StripFileExtensions(sDesc)) + tOptions.TagCase('</A>'); //will replace Selected Text, or Insert Text if none selected AddText(sText, '', True); rtfDoc.SetFocus; end; (* procedure TfrmDoc.AddToRecent; begin AddToRecentFiles(sDocFileName, mnuFile, RecentFilesItemClick); MainForm.ReadRecent; end; *) procedure TfrmDoc.DocHeading(iHeading: Integer); var iStart: Integer; iEnd: Integer; sNew: String; begin if iHeading = 0 then begin if SelLength > 0 then begin iStart := Pos('<h', LowerCase(SelText)); if iStart > 0 then begin sNew := Copy(SelText, iStart + 4, SelLength); iEnd := Pos('</h', LowerCase(sNew)); if iEnd > 0 then sNew := Copy(sNew, 0, iEnd - 1); SelText := sNew; end; end; end else AddText(tOptions.TagCase('<H') + IntToStr(iHeading) + '>' + SelText, tOptions.TagCase('</H') + IntToStr(iHeading) + '>', False); end; procedure TfrmDoc.InsertTable; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmTableWizard, frmTableWizard); finally Screen.Cursor := crDefault; end; frmTableWizard.ShowModal; end; procedure TfrmDoc.QuickTable(sTableText: String); begin SelText := sTableText; end; procedure TfrmDoc.DocFrameWizard; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmFrameWizard, frmFrameWizard); finally Screen.Cursor := crDefault; end; frmFrameWizard.ShowModal; if frmFrameWizard.ModalResult = mrOK then begin SelText := frmFrameWizard.sFrameText; if (Pos('<BODY', Uppercase(Text)) > 0) or (Pos('</BODY>', Uppercase(Text)) > 0) then frmFrameWizard.InsertNoFrames; end; frmFrameWizard.release; end; procedure TfrmDoc.HideToolbarShit(bOnlySelectionChanged : Boolean); begin //Check available features { Standard } if rtfDoc <> nil then begin EnableToolbarButton(SAVE_BUTTON, (bDocDirty) or (Length(FileName) = 0)); EnableToolbarButton(CUT_BUTTON, (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd)); EnableToolbarButton(COPY_BUTTON, (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd)); // MainForm.buttUndo.Enabled := Document.CanUndo; // MainForm.buttRedo.Enabled := Document.CanRedo; EnableToolbarButton(UNDO_BUTTON, Document.UndoManager.CanUndo); MainForm.buttUndoList.Enabled := Document.UndoManager.CanUndo; EnableToolbarButton(REDO_BUTTON, Document.UndoManager.CanRedo); MainForm.buttRedoList.Enabled := Document.UndoManager.CanUndo; EnableToolbarButton(PASTE_BUTTON, Clipboard.HasFormat(CF_TEXT)); MainForm.DirtyBird(True); if not bOnlySelectionChanged then MainForm.HideShit; end; end; procedure TfrmDoc.MainViewRightClick(X, Y: Integer); function ValidateSpellText(sCheckSpell:string):boolean; var ipos: Integer; bIsWordGood: Boolean; begin ipos:=1; bIsWordGood:=True; if Trim(sCheckSpell) = '' then bIsWordGood:=False; while (ipos <= length(sCheckSpell)) and (bIsWordGood = True) do begin if not((ord(sCheckSpell[ipos]) >=65) AND (ord(sCheckSpell[ipos]) <=90) or ((ord(sCheckSpell[ipos]) >=97) AND (ord(sCheckSpell[ipos]) <=122))) then bIsWordGood:=False; ipos:=ipos+1; end; Result := bIsWordGood; end; { MainViewRightClick } const maxSuggBfr = 1024; maxSuggestions = 16; var { Evil Physicsboy Spellchecker } NewMenuItem: TMenuItem; //ImagePreviewItem : TMenuItem; wrd: array[0..SSCE_MAX_WORD_SZ] of SSCE_CHAR; replWrd: array[0..SSCE_MAX_WORD_SZ] of SSCE_CHAR; suggBfr: array[0..maxSuggBfr] of Char; scores: array[0..maxSuggestions] of S16; suggWord: string[SSCE_MAX_WORD_SZ]; i{, n} : Integer; {Hint} scorePtr: PS16; result: S16; //sID: S16; sWord: String; { Other } tElement: Variant; iStart: Integer; iPos: Integer; P, Q: TPoint; sTag: String; sFile : String; //gutterItems : Array[0..2] of TMenuItem; //NumberItems : Array[0..4] of TMenuItem; //popGutter : TPopupMenu; begin if rtfDoc.PointInGutter(X, Y) then DisplayGutterPopup(X,Y) else begin iPos := rtfDoc.FindPositionFromPoint(X, Y); popMainEdit.Visible := False; popEditColor.Visible := False; nMainEdit.Visible := False; popPSP.Visible := False; popMainPreview.Visible := False; popMainHREF.Visible := False; if iPos <> Document.Length then begin while popViewMain.Items[popViewMain.Items.Count-1].Name <> 'Poste_restante' do begin popViewMain.Items[popViewMain.Items.Count-1].Free; end; popViewMain.Items[popViewMain.Items.Count-1].Visible:=False; tElement := Document.GetElementAt(iPos, iStart); //Check if a colour is highlighted if (Copy(SelText,1,1) = '#') and (Length(SelText) = 7) then begin popEditColor.Caption := 'Edit Color'; popEditColor.Visible := True; nMainEdit.Visible := True; end; if tElement.Type = HTMLSYNTAXELEMENT_TEXT then begin //sID := SSCE_OpenSession; //sID := SSCE_GetSid; if sID > 0 then begin //function to parse for spaces around current spot //sWord := GetWord(iPos, iStart, iStart + tElement.Length); sWord := GetWordAtPos(iPos, iSpellStart, iSpellEnd); if ValidateSpellText(sWord) then begin if (Trim(sWord) <> '') and (slSpellAddList.IndexOf(Trim(sWord)) = -1) then //not almost in dictionary begin StrPCopy(wrd, sWord); result := SSCE_CheckWord(sID, 0, wrd, replWrd, Sizeof(replWrd)); if result<0 then // showmessage('Spell Checker Error') else begin if ((result and SSCE_MISSPELLED_WORD_RSLT) <> 0) then begin scorePtr := @scores[0]; result := SSCE_Suggest(sID, wrd, 3, suggBfr, maxSuggBfr, scorePtr,maxSuggestions); if (result < 0) then begin //ShowMessage('Spell Checker Suggestion Error: ' + IntToStr(result)); end else begin {The set of suggestions is returned as a collection of words,} {separated by nulls. The last word is marked by a double null.} i := 0; //n := 0; {Hint} popViewMain.Items[popViewMain.Items.Count-1].Visible:=True; while (suggBfr[i] <> #0) do begin suggWord := ''; while (suggBfr[i] <> #0) do begin suggWord := suggWord + suggBfr[i]; i := i + 1; end; NewMenuItem := TMenuItem.Create(popViewMain); NewMenuItem.OnClick := CorrectWord; NewMenuItem.Caption := suggWord; popViewMain.Items.Insert(popViewMain.Items.Count, NewMenuItem); i := i + 1; //n := n + 1; {Hint} end; end end; { - don't worry about this code - its okay to leave it out I think. I'll check it later: if ((result and SSCE_SUGGEST_WORD_RSLT) <> 0) then begin showmessage('Suggest replacing ' + Edit1.Text +' with ' + StrPas(replWrd)); end; } end; end; end; //SSCE_CloseSession(sID); end; end {else if (tElement.Type = HTMLSYNTAXELEMENT_COLORVALUE) then begin popMainEdit.Caption := 'Edit Color'; popMainEdit.Visible := True; nMainEdit.Visible := True; //Set Right Click Values to Element bounds tCurrentElement.iStart := iStart; tCurrentElement.iLength := iStart + tElement.Length; tCurrentElement.iType := tElement.Type; tCurrentElement.sTagName := 'Edit Color'; end //Can't do this yet - Kin } else if tElement.Type = HTMLSYNTAXELEMENT_COMMENT then begin //comment popMainEdit.Caption := 'Remove Comment Tags'; popMainEdit.Visible := True; nMainEdit.Visible := True; //Set Right Click Values to Element bounds tCurrentElement.iStart := iStart; tCurrentElement.iLength := iStart + tElement.Length; tCurrentElement.iType := tElement.Type; tCurrentElement.sTagName := 'Remove Comment Tags'; end {else if tElement.Type = HTMLSYNTAXELEMENT_ERROR then begin //error ShowMessage('Error'); end} else if ((tElement.Type = HTMLSYNTAXELEMENT_TAG) or (tElement.Type = HTMLSYNTAXELEMENT_ERROR)) then begin //tag sTag := Document.GetTextRange(iStart, iStart + tElement.Length); if IsTagEditable(sTag) then begin tCurrentElement.sTagName := GetTagName(sTag); popMainEdit.Caption := 'Edit ' + tCurrentElement.sTagName + ' Tag'; popMainEdit.Visible := True; nMainEdit.Visible := True; //Set Right Click Values to Element bounds tCurrentElement.iStart := iStart; tCurrentElement.iLength := iStart + tElement.Length; tCurrentElement.iType := tElement.Type; If tCurrentElement.sTagName = 'Image' then begin popMainPreview.Visible := True; //if tReg.OpenTo(INI_PARTNER_PSP, False) then {$IFNDEF HOTDOG_STAND_ALONE} popPSP.Visible := True; {$ENDIF} end; end; if Length(GetTag(sTag, '<a href', '>')) > 0 then begin sTag := ReplaceString(sTag, '<a href =', '<a href='); sTag := ReplaceString(sTag, '<a href= ', '<a href='); sFile := URLToFile(GetAttribute(sTag, 'href')); if Pos('#', sFile) > 0 then sFile := Copy(sFile, 0, Pos('#',sFile)-1); //if (not(FileExists(sFile))) and (FileName <> '') then sFile := RelativeToAbsolute(Filename, sFile); if FileExists(sFile) then begin popMainHREF.Visible := True; popMainHREF.Hint := sFile; end; end; end else begin //fuck knows.... tCurrentElement.iType := HTMLSYNTAXELEMENT_INVALID; end; end; P := Point(X, Y); Q := rtfDoc.ClientToScreen(P); popViewMain.PopUp(Q.X, Q.Y); end; end; procedure TfrmDoc.CorrectWord(Sender: TObject); begin Document.ReplaceText(iSpellStart, iSpellEnd - iSpellStart, TMenuItem(Sender).Caption); while popViewMain.Items[popViewMain.Items.Count-1].Name <> 'Poste_restante' do begin popViewMain.Items.Remove(popViewMain.Items[popViewMain.Items.Count-1]); popViewMain.Items[popViewMain.Items.Count-1].Free; end; popViewMain.Items[popViewMain.Items.Count-1].Visible:=False; end; procedure TfrmDoc.SetCursorPos(iPos: Integer); begin //rtfDoc.SelectionStart := iPos; //rtfDoc.SelectionEnd := iPos; rtfDoc.SetSelection(iPos, iPos); end; procedure TfrmDoc.SetSelection(iStart, iLength: Integer); begin rtfDoc.SetSelection(iStart, iStart + iLength); rtfDoc.ScrollCaretToView; end; procedure TfrmDoc.DocDelete; //cunt begin if SelLength > 0 then SelText := ''; end; procedure TfrmDoc.popMainEditClick(Sender: TObject); begin DocEditTag; end; procedure TfrmDoc.DocEditTag; begin rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength); if tCurrentElement.sTagName = 'Image' then InsertImage else if tCurrentElement.sTagName = 'Hypertext Link' then InsertLink(insLink) else if tCurrentElement.sTagName = 'Email Link' then InsertLink(insEmail) else if tCurrentElement.sTagName = 'FTP Link' then InsertLink(insFTP) else if tCurrentElement.sTagName = 'News Link' then InsertLink(insNews) else if tCurrentElement.sTagName = 'Line' then InsertLine else if tCurrentElement.sTagName = 'Table' then InsertTable else if tCurrentElement.sTagName = 'Font' then DocFont(True) else if tCurrentElement.sTagName = 'Remove Comment Tags' then DocComment else if Pos('List', tCurrentElement.sTagName) > 0 then InsertList else if Pos('Font', tCurrentElement.sTagName) > 0 then InsertList else if tCurrentElement.sTagName = 'Body' then begin DocProperties; end {else if tCurrentElement.sTagName = 'Edit Color' then begin ShowMessage('Edit Color');//DocColor; end //can't do this yet - kin} else if tCurrentElement.sTagName = 'Paragraph' then //todo DocPara; end; function TfrmDoc.CheckDirty: Boolean; begin Result := bDocDirty; end; function TfrmDoc.GetElementAt(iPosition: Integer; var iStart: Integer; var sElement: String): Variant; (* Returns the HTML Element at iPosition in the document. iStart will be set to the starting position of the element. sElement will be filled with the Element. *) var sResult: Variant; begin sResult := Document.GetElementAt(iPosition, iStart); sElement := Document.GetTextRange(iStart, iStart + sResult.Length); //Return Data Result := sResult; end; procedure TfrmDoc.lmdDocMRUClick(Sender: TObject; const aValue: string; var Remove: Boolean); begin //MainForm.lmdMRU.CheckSharedFile(aValue); end; procedure TfrmDoc.rtfDocMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin BringToFront; end; function TfrmDoc.CreateTagsDropText(Source: TObject; sHighlighted : String):string; var sTemp,sAttrTemp:string; vElementLookup,vAttrLookup:variant; i:integer; iAttrCount:integer; begin sTemp:=(source as TCustomTreeView).selected.text; if sTemp[1]='<' then begin sTemp:='<'+chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>'); if (source as TCustomTreeView).selected.expanded then begin vElementLookup := MainForm.vTagsLookup.Lookup(chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>')); iAttrCount:=vElementLookup.ElementCount; if iAttrCount>0 then begin for i:=0 to iAttrCount-1 do begin sAttrTemp:=vElementLookup.ElementName(i); sTemp:=sTemp+' '+sAttrTemp; // add attr name vAttrLookup:=vElementLookup.Lookup(sAttrTemp); // get attr type case vAttrLookup.ValueType of 1: sTemp:=sTemp+'='; 2: sTemp:=sTemp+'=""'; 3: sTemp:=sTemp+'='; 4: sTemp:=sTemp+'=""'; 5: sTemp:=sTemp+'="#"'; end; end; end; end; sTemp:=sTemp+'>' + sHighlighted; vElementLookup:= MainForm.vTagsPairLookup.lookup(chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>')); try if vElementLookup.AlwaysRequired then sTemp:=sTemp+'</'+chopbefore(chopafter((source as TCustomTreeView).selected.text,'<'),'>')+'>'; except end; end; result:=sTemp; end; procedure TfrmDoc.StripTags; //procedure TfrmDoc.DocExportToText; (* Local Procedures *) function GetFileName: String; var tDlgSave: TFileDialog; begin tDlgSave := TFileDialog.Create(Self); try begin //tdlgSave.UseWinDialog := not(tOptions.UseCustomFileDialog); tdlgSave.OpenFile := False; tDlgSave.InitialDir := tOptions.DocumentDirectory; tDlgSave.DefaultExt := tOptions.DefaultDocExtension; tDlgSave.WinOptions := [ofOverwritePrompt, ofHideReadOnly]; tDlgSave.CustomOptions := [ptofOverwritePrompt, ptofHideReadOnly]; tDlgSave.Filter := 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*'; if tDlgSave.Execute then begin Result := tDlgSave.FileName; end else Result := ''; end finally tDlgSave.Free; end; end; (* DocExportToText *) var sTag: String; iStart: integer; begin iStart := 0; repeat sTag := GetNextTag(iStart); if Length(sTag) > 0 then begin Document.ReplaceText(iStart, Length(sTag), ''); end; until Length(sTag) = 0; end; function TfrmDoc.ReplaceAll(sFind, sReplace: String): Integer; var iLastPos: Integer; iPos: Integer; begin Result := 0; iLastPos := 0; iPos := 0; //MrKistic - 15 September 1997 while (iLastPos < Document.Length - 1) and (iPos <> -1) do begin iPos := Find(sFind, iLastPos, True, False); if iPos > -1 then begin //string found begin Document.ReplaceText(iPos, Length(sFind), sReplace); iLastPos := iPos + Length(sReplace); Inc(Result); end; end; end; end; procedure TfrmDoc.DocPublishToFileOrScreen; var iChanges : Integer; sPublishDir : String; begin if tOptions.PublishToDir then begin iChanges := PublishDocumentInAShouseyManner; sPublishDir := FilePath(tOptions.PublishDirectory, ExtractFileName(sDocFileName)); if iChanges > -1 then MessageDlg(Format('The HotDog Publisher has finished with this document. %d changes were made to %s .', [iChanges, sPublishDir]), mtInformation, [mbOK], 0); end else begin if tOptions.ShowPublishMsg then begin Application.CreateForm(TfrmPublishMsg,frmPublishMsg); frmPublishMsg.ShowModal; if frmPublishMsg.ModalResult = mrOk then DocPublish; frmPublishMsg.Free; end else DocPublish; end; end; procedure TfrmDoc.DocPublish; { DocPublish } var iCount, iChanges: Integer; //iLastPos : Integer; sFind, sReplace: String; slItems: TStringList; begin Status('Publishing document...'); iChanges := 0; begin slItems := TStringList.Create; try tOptions.ReadPubReplaceStrings(slItems); for iCount := 0 to slItems.Count - 1 do begin sFind := ChopBefore(slItems.Strings[iCount], '='); sReplace := slItems.Values[sFind]; iChanges := iChanges + ReplaceAll(sFind, sReplace); end; if tOptions.PublishTagCase > 0 then begin iChanges := iChanges + DocConvertTagCase(True, True); end; if tOptions.PublishExtChar then begin iChanges := iChanges + DocConvertExtChar; end; if tOptions.PublishCR then begin iChanges := iChanges + DocConvertCR(False); end; if tOptions.PublishSlash then begin iChanges := iChanges + DocConvertSlash; end; SetFileFormat(DocEOLType(tOptions.PublishFileFormat)); iChanges := iChanges + PublishFields; //WriteWholeFile(sPubFile, sDocument); finally slItems.Free; end; end; MessageDlg(Format('The HotDog Publisher has finished with this document. %d changes were made.', [iChanges]), mtInformation, [mbOK], 0); Status(''); end; {-= MrKistic - 19 November 1997 =-} function TfrmDoc.PublishDocumentInAShouseyManner: Integer; { Local Procedure } function ShitReplaceAll(var sText: String; sFind, sReplace: String): Integer; var iLastPos: Integer; iPos: Integer; begin Result := 0; iLastPos := 0; iPos := -1; while (iLastPos < Length(sText)) and (iPos <> 0) do begin iPos := PosIn(sFind, sText, iLastPos); if iPos > 0 then begin begin Delete(sText, iPos, Length(sFind)); Insert(sReplace, sText, iPos); iLastPos := iPos + Length(sReplace); Inc(Result); end; end; end; end; function ShitFindTagInList(sChar: String): String; var iCount: Integer; begin iCount := 0; Result := ''; //-- Sav 23-03-97 while iCount <= High(ExtendedChars) do //while iCount <= MainForm.lvExtChar.Items.Count - 1 do begin if sChar = ExtendedChars[iCount][0] then //if sChar = MainForm.lvExtChar.Items.Item[iCount].Caption then begin if Pos('>', ExtendedChars[iCount][1]) = 0 then //if Pos('>', MainForm.lvExtChar.Items.Item[iCount].SubItems[0]) = 0 then Result := ExtendedChars[iCount][1] + ';' //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0] + ';' else Result := ExtendedChars[iCount][1]; //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0]; end; Inc(iCount); end; end; function ShitConvertExtChar(ShitDocument: Variant): Integer; var sChar, sNewTag: String; iCount, iStart: Integer; tElement: Variant; iChanges: Integer; begin iChanges := 0; iCount := 0; while iCount < ShitDocument.Length -1 do begin try sChar := ShitDocument.GetTextRange(iCount, iCount + 1); sChar := Trim(sChar); if Length(sChar) > 0 then begin tElement := ShitDocument.GetElementAt(iCount, iStart); if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then iCount := iCount + tElement.Length - 1 else if (Ord(sChar[1]) > 122) or (sChar = '>') or (sChar = '<') or (sChar='&') or (sChar = '"') then begin //find in list and replace with tag sNewTag := ShitFindTagInList(sChar); if sNewTag <> '' then begin ShitDocument.ReplaceText(iCount, Length(sChar), sNewTag); iCount := iCount + Length(sNewTag) -1; Inc(iChanges); end; end; end; Inc(iCount); except //nada end; end; Result := iChanges; end; { PublishDocumentInAShouseyManner } var iCount, iChanges: Integer; //iPos: Integer; sFind, sReplace: String; sDocument: String; slItems: TStringList; bContinue: Boolean; OleSysError: EOleSysError; OleException: EOleException; sPubFile: String; ShitDocument: Variant; begin if Trim(sDocFileName) = '' then begin if MessageDlg('This document must be saved before you can publish to a directory.', mtInformation, [mbOk,mbCancel],0) = mrOK then Save; end; if Trim(sDocFileName) = '' then begin Result := -1; exit; end; {$I+} if Not DirectoryExists(tOptions.PublishDirectory) then mkDir(tOptions.PublishDirectory); {$I-} sPubFile := FilePath(tOptions.PublishDirectory, ExtractFileName(sDocFileName)); sDocument := Document.Text; WriteWholeFile(sPubFile, sDocument); try ShitDocument := CreateOLEObject('Sausage.HTMLTextDocument.2'); ShitDocument.SetSyntaxManager(SyntaxManager); ShitDocument.Reparse; //FTPStatus('Converting Extended Characters...'); while ShitDocument.Formatting do Application.ProcessMessages; bContinue := True; except on e: Exception do begin //if DEBUG_FLAG then begin if e is EOleException then begin OleException := (e as EOleException); if DEBUG_FLAG then ShowMessage(OleException.Message); end else if e is EOleSysError then begin OleSysError := (e as EOleSysError); if DWord(OleSysError.ErrorCode) = CO_E_CLASSSTRING then //-- Sav D4 begin if DEBUG_FLAG then ShowMessage('Invalid class string : The file "HTMLDocumentSvr.dll" has not been registered correctly.'); end else if DWord(OleSysError.ErrorCode) = REGDB_E_CLASSNOTREG then //-- Sav D4 begin if DEBUG_FLAG then ShowMessage('Class not registered : The file "HTMLDocumentSvr.dll" has not been registered correctly.'); end else if OleSysError.ErrorCode = ERROR_DLL_NOT_FOUND then begin if DEBUG_FLAG then ShowMessage('DLL not found : The file "HTMLDocumentSvr.dll" has been registered but could not be loaded correctly.'); end else if DEBUG_FLAG then ShowMessage(OleSysError.Message); end else if DEBUG_FLAG then ShowMessage(e.message); end; bContinue := False; end; end; iChanges := 0; if bContinue then begin try ShitDocument.LoadFromFile(sPubFile); if tOptions.PublishExtChar then begin iChanges := ShitConvertExtChar(ShitDocument); end; if tOptions.PublishTagCase = 1 then iChanges := iChanges + ShitDocument.MakeAllNameUpper else if tOptions.PublishTagCase = 2 then iChanges := iChanges + ShitDocument.MakeAllNameLower; ShitDocument.EOLType := DocEOLType(tOptions.PublishFileFormat); //-- Sav Make sure all the publish fields are processed. ShitDocument.Text := PublishText(ShitDocument.Text, 'PUBLISH', sPubFile, iChanges); ShitDocument.SaveToFile(sPubFile); except //nada end; end; sDocument := ReadWholeFile(sPubFile); if Length(sDocument) > 0 then begin slItems := TStringList.Create; try tOptions.ReadPubReplaceStrings(slItems); for iCount := 0 to slItems.Count - 1 do begin sFind := ChopBefore(slItems.Strings[iCount], '='); sReplace := slItems.Values[sFind]; iChanges := iChanges + ShitReplaceAll(sDocument, sFind, sReplace); end; if tOptions.PublishCR then begin iChanges := iChanges + ShitReplaceAll(sDocument, #13#10, ''); end; if tOptions.PublishSlash then begin iChanges := iChanges + ShitReplaceAll(sDocument, '\', '/'); end; WriteWholeFile(sPubFile, sDocument); finally slItems.Free; end; end; Result := iChanges; if sDocFilename = sPubFile then Text := sDocument; end; function TfrmDoc.DocConvertSlash: Integer; begin Result := ReplaceAll('\', '/'); end; function TfrmDoc.DocConvertCR(bSelText : Boolean): Integer; begin Result := 0; if bSelText then SelText := ReplaceString(SelText, #13#10, '') else Result := ReplaceAll(#13#10, ''); end; function TfrmDoc.DocConvertExtChar: Integer; { Local } function FindTagInList(sChar: String): String; var iCount: Integer; begin iCount := 0; Result := ''; //--Sav 23-03-97 while iCount <= High(ExtendedChars) do //while iCount <= MainForm.lvExtChar.Items.Count - 1 do begin if sChar = ExtendedChars[iCount][0] then //if sChar = MainForm.lvExtChar.Items.Item[iCount].Caption then begin if Pos('>', ExtendedChars[iCount][1]) = 0 then //if Pos('>', MainForm.lvExtChar.Items.Item[iCount].SubItems[0]) = 0 then Result := ExtendedChars[iCount][1] + ';' //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0] + ';' else Result := ExtendedChars[iCount][1]; //Result := MainForm.lvExtChar.Items.Item[iCount].SubItems[0]; end; Inc(iCount); end; end; function FindExistingTag(sTag: String): Boolean; var iCount: Integer; begin iCount := 0; Result := False; sTag := Trim(sTag); if (Copy(sTag, 1, 2) = '') and (Copy(sTag, 6, 1) = ';') then Result := True else begin //-- Sav 23-03-97 sTag := Copy(sTag, 1, Length(sTag) - 1); while iCount <= High(ExtendedChars) do //while iCount <= MainForm.lvExtChar.Items.Count - 1 do begin if sTag = ExtendedChars[iCount][1] then //if sTag = MainForm.lvExtChar.Items.Item[iCount].SubItems[0] then Result := True; Inc(iCount); end; end; end; function GetWord(iPos, iEnd: Integer): String; var sChar: String; begin Result := ''; while iPos < iEnd do begin sChar := Document.GetTextRange(iPos, iPos + 1); Result := Result + sChar; if (sChar = ';') or (sChar = ' ') then iPos := iEnd else Inc(iPos); end; end; function GetAltWord(sAltText:string;iPos:integer): String; (*mg261196*) var sChar: String; iEnd:integer; bEnd:boolean; begin Result := ''; bEnd:=false; iEnd:=length(sAltText); repeat begin sChar := Copy(sAltText, iPos,1); Result := Result + sChar; if (sChar = ';') or (sChar = ' ') then bEnd:=true else Inc(iPos); end; until (iPos > iEnd) or bEnd; end; var sChar, sNewTag: String; sOldTag, sAltTag, sNewAltTag: String; iCount, iStart, iAltCount: Integer; tElement: Variant; iChanges, iPos: Integer; begin {-= MrKistic - 20 November 197 =-} iChanges := 0; iCount := 0; while iCount < Document.Length -1 do begin try sChar := Document.GetTextRange(iCount, iCount + 1); sChar := Trim(sChar); if Length(sChar) > 0 then begin tElement := Document.GetElementAt(iCount, iStart); if tElement.Type <> HTMLSYNTAXELEMENT_TEXT then begin if tElement.Type = HTMLSYNTAXELEMENT_TAG then begin sNewTag := Document.GetTextRange(iStart, iStart + tElement.Length); if GetTagName(sNewTag) = 'Image' then begin sOldTag := sNewTag; iPos := Pos('alt', LowerCase(sNewTag)); if iPos > 0 then begin sAltTag := GetAttribute(sNewTag, 'alt'); sNewAltTag := ''; //Loop thru alt tag and convert it, then replace it in the document if Length(sAltTag) > 0 then begin (*mg261197 for iAltCount := 1 to Length(sAltTag) do *) iAltCount:=1; while iAltCount<Length(sAltTag)+1 do begin (*mg261197 if not(FindExistingTag(Copy(sAltTag, iAltCount, Length(sAltTag)))) then *) sNewTag:=GetAltWord(sAltTag,iAltCount); if not(FindExistingTag(sNewTag)) then begin sChar := sAltTag[iAltCount]; if (Ord(sChar[1]) > 122) or (sChar = '>') or (sChar = '<') or (sChar='&') or (sChar = '"') then begin //find in list and replace with tag sNewTag := FindTagInList(sChar); if sNewTag <> '' then begin sNewAltTag := sNewAltTag + sNewTag; Inc(iChanges); end; end else sNewAltTag := sNewAltTag + sChar; inc(iAltCount); end else begin sNewAltTag := sNewAltTag + sNewTag; iAltCount:=iAltCount+length(sNewTag); end; end; sNewTag := sOldTag; ReplaceAttribute(sNewTag, 'alt', sNewAltTag); Document.ReplaceText(iCount, Length(sOldTag), sNewTag); end; iCount := iCount + Length(sNewTag)-1; end else iCount := iCount + tElement.Length - 1; end else iCount := iCount + tElement.Length - 1; end else iCount := iCount + tElement.Length - 1; end else if (Ord(sChar[1]) > 122) or (sChar = '>') or (sChar = '<') or (sChar='&') or (sChar = '"') then begin //Check that it isn't part of an already expanded char sNewTag := GetWord(iCount, iStart + tElement.Length); if not(FindExistingTag(sNewTag)) then begin //find in list and replace with tag sNewTag := FindTagInList(sChar); if sNewTag <> '' then begin Document.ReplaceText(iCount, Length(sChar), sNewTag); iCount := iCount + Length(sNewTag) -1; Inc(iChanges); end; end; end; end; Inc(iCount); except //nada end; end; Result := iChanges; end; procedure TfrmDoc.DocConvertCase(bUpperCase : Boolean); begin if bUpperCase then SelText := UpperCase(SelText) else SelText := LowerCase(SelText); end; function TfrmDoc.DocConvertTagCase(bPublishing, bUpperCase : Boolean) : Integer; begin //bUpperCase is only read if we are not publishing, because then the preference is read instead. result := 0; if bPublishing then begin if tOptions.PublishTagCase = 1 then result := Document.MakeAllNameUpper else if tOptions.PublishTagCase = 2 then result := Document.MakeAllNameLower; end else begin if bUppercase then Document.MakeAllNameUpper else Document.MakeAllNameLower; MainForm.DirtyBird(True); HideToolbarShit(True); end; end; function TfrmDoc.DocPublishAndSave : Integer; { Local Procedure } function ReplaceAll(sFind, sReplace: String): Integer; var iLastPos: Integer; iPos: Integer; begin Result := 0; iLastPos := 0; iPos := 0; while (iLastPos < (Document.Length - 1)) and (iPos <> -1) do begin iPos := Find(sFind, iLastPos, True, False); if iPos > -1 then begin //string found //check for text only {tElement := Document.GetElementAt(iPos, iStart); if tElement.Type = HTMLSYNTAXELEMENT_TEXT then} begin Document.ReplaceText(iPos, Length(sFind), sReplace); iLastPos := iPos + Length(sReplace); Inc(Result); end; end; end; end; { DocPublishAndSave } var iCount, iChanges: Integer; //iLastPos : Integer; {Hint} sFind, sReplace: String; slReplace: TStringList; lDetails: TList; Details: ^TReplaceDetails; begin {-= MrKistic - 19 November 1997 =-} {-= new =-} {if tOptions.PublishToDir and (DirectoryExists(tProject.PublishDirectory)) then begin iChanges := PublishDocumentInAShouseyManner end else} begin iChanges := 0; begin lDetails := TList.Create; try tProject.ReadPubReplaceDetails(lDetails); for iCount := 0 to lDetails.Count - 1 do begin Details := lDetails[iCount]; sFind := Details.sFrom; if Details.bUseFile then begin if FileExists(Details.sFileName) then begin slReplace := TStringList.Create; try slReplace.LoadFromFile(Details.sFileName); iChanges := iChanges + ReplaceAll(sFind, slReplace.Text); finally slReplace.Free; end; end; end else if Length(Details.sFrom) > 0 then begin sReplace := Details.sTo; iChanges := iChanges + ReplaceAll(sFind, sReplace); end; end; if tProject.PublishCR then begin iChanges := iChanges + DocConvertCR(False); end; SetFileFormat(DocEOLType(tOptions.PublishFileFormat)); if tProject.PublishSlash then begin iChanges := iChanges + DocConvertSlash; end; if tOptions.PublishExtChar then begin iChanges := iChanges + DocConvertExtChar; end; iChanges := iChanges + PublishFields; finally lDetails.Free; end; end; Save; end; Result := iChanges; end; { Page Sniffer } function TfrmDoc.SniffElements(sResult: TStringList; bIncludePositions: Boolean): Integer; {***************************************************************************** * Module: fDoc * Version: 1.1 * Procedure: SniffElements * Description: Searches Document for tags and populates sResult with em' *****************************************************************************} var tElement: Variant; iPos, iStart, iEnd: Integer; begin sResult.Clear; while iPos < (Document.Length -1) do begin tElement := Document.GetElementAt(iPos, iStart); iEnd := iStart + tElement.Length; if iEnd = Document.Length then iEnd := iEnd - 1; if tElement.Type = HTMLSYNTAXELEMENT_TAG then begin if bIncludePositions then sResult.Add(IntToStr(iStart)+ ',' + Document.GetTextRange(iStart, iEnd)) else sResult.Add(Document.GetTextRange(iStart, iEnd)); end; iPos := iEnd; end; //while Result := sResult.Count; end; procedure TfrmDoc.UpdateTagColors; var sColorValues: TStringList; i: Integer; begin //LockWindowUpdate(rtfDoc.Handle); sColorValues:=Tstringlist.create; try begin if tReg.OpenTo(INI_HTML_TAGS, False) then begin if tReg.OpenKey(INI_TAGS_COLOR, False) then begin tReg.GetSectionValues(sColorValues); //rtfDoc.RemoveAllExceptionTags; for i := 0 to sColorValues.Count - 1 do begin if sColorValues.Names[i] <> 'Default' then rtfDoc.AddExceptionTag(sColorValues.Names[i],HTMLToColor(GetNewForeColor(sColorValues.Values[sColorValues.Names[i]])), HTMLToColor(GetNewBackColor(sColorValues.Values[sColorValues.Names[i]]))) else begin if spdTag.Down then begin if tOptions.ColorTagBack <> '' then rtfDoc.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack) else rtfDoc.FormatBackcolor[4] := HTMLToColor(GetNewBackColor(sColorValues.Values['Default'])); if tOptions.ColorTagText <> '' then rtfDoc.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText) else rtfDoc.FormatTextcolor[4] := aColors[GetForeColor(sColorValues.Values['Default'])]; end; end; end; end; end; if spdTag.Down then begin rtfDoc.Repaint; //rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX; //rtfDoc.HighlightStyle := HTMLEDITVIEW_TAGS; //kin 190997 end else begin if (tOptions.ColorTagBack <> '') then rtfDoc.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack) else rtfDoc.FormatBackcolor[4] := clWhite; if (tOptions.ColorTagText <> '') then rtfDoc.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText) else rtfDoc.FormatTextcolor[4] := clBlue; //Sav 230997 end; end finally sColorValues.free; //LockWindowUpdate(0); end; end; procedure TfrmDoc.UpdateSyntax; begin Status('Reloading Syntax Files...'); Document.Reparse; end; procedure TfrmDoc.rtfDocMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbRight then begin Screen.Cursor := crHourGlass; try MainViewRightClick(X, Y); finally Screen.Cursor := crDefault; end; end; end; procedure TfrmDoc.rtfDocKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin try if (ssShift in Shift) and (Key = 13) then begin DocBreak; Key := 0; end else if (ssCtrl in Shift) and (Key = 32) then begin InsertText(' ', SelStart); Key := 0; end else if (ssAlt in Shift) and (Key = 13) then begin DocPara; //InsertText('<P>', SelStart); Key := 0; end else //Test for preview functions if (Key = VK_F9) then begin try if (MainForm is TfrmMainRover) then begin if ssCtrl in Shift then (MainForm as TfrmMainRover).PosRefreshRover(PreviewFilename, Text) else DocPreviewWithLastBrowser; end else DocPreviewWithLastBrowser; except end; end else // Sav 01-09-97 //When F1 is pressed, bring up the main help screen. if Key = VK_F1 then begin application.helpfile := filepath(ExtractFileDir(Application.ExeName), 'HotDog5.hlp'); application.helpCommand(Help_Finder,0); end else //Find if Key = VK_F3 then begin DocFindF3; end else if (ssCtrl in Shift) and (Key = 13) then begin if Assigned(MainForm.propSheet) then MainForm.PropSheet.SetFocus; end else if (Shift = [ssAlt]) and ((Key >= 48) and (Key <= 57)) then begin if Assigned(MainForm.strClipboard) then PasteFromClipboard(Key); end else if (Shift = [ssAlt,ssShift]) and ((Key >= 48) and (Key <= 57)) then begin if Assigned(MainForm.strClipboard) then CopyToClipboard(Key); end; except end; end; procedure TfrmDoc.rtfDocEditModeToggled(Sender: TObject; bOverwrite: Wordbool); begin spdInsert.Down := bOverwrite; end; procedure TfrmDoc.rtfDocDocumentChanged(Sender: TObject; nAction: Smallint; nChangeAt, nChangeCount: Integer); begin if (bFirstLoaded) and (text <> '') then begin if (Owner is TfrmMainRover) then begin (Owner as TfrmMainRover).PosRefreshRover(PreviewFilename, Text); end; bFirstLoaded := False; end; bRoverDirty := True; bDocDirty := True; end; procedure TfrmDoc.ClearCurrentElement; begin tCurrentElement.iType := HTMLSYNTAXELEMENT_INVALID; tCurrentElement.sTagName := ''; tCurrentElement.iStart := 0; tCurrentElement.iLength := 0; end; function TfrmDoc.CanUndo: Boolean; begin if bSetup then //Result := Document.CanUndo Result := Document.UndoManager.CanUndo //kin 190997 else Result := False; end; function TfrmDoc.GetUndoCount : Integer; begin try result := Document.UndoManager.UndoCount; except result := 0; end; end; function TfrmDoc.GetUndoItemText(Index : Integer) : String; begin try If (Index > -1) and (Index <= (GetUndoCount - 1)) then result := Document.UndoManager.UndoAction[Index].Description; except result := ''; end; end; procedure TfrmDoc.UndoTo(Index : Integer); begin try If (Index > -1) and (Index <= (GetUndoCount - 1)) then Document.UndoManager.UndoTo(Document.UndoManager.UndoAction[Index]); except end; end; function TfrmDoc.GetNextUndoText : String; //just returns the description of the next undo begin try if CanUndo then begin Result := Document.UndoManager.UndoAction[GetUndoCount-1].Description; end; except Result := ''; end; end; function TfrmDoc.CanRedo: Boolean; begin try if bSetup then //Result := Document.CanRedo Result := Document.UndoManager.CanRedo //kin 190997 else Result := False; except Result := False; end; end; function TfrmDoc.GetRedoCount : Integer; begin try result := Document.UndoManager.RedoCount; except result := 0; end; end; procedure TfrmDoc.RedoTo(Index : Integer); begin try If (Index > -1) and (Index <= (GetRedoCount - 1)) then Document.UndoManager.RedoTo(Document.UndoManager.RedoAction[Index]); except end; end; function TfrmDoc.GetRedoItemText(Index : Integer) : String; begin try If (Index > -1) and (Index <= (GetRedoCount - 1)) then result := Document.UndoManager.RedoAction[Index].Description; except result := ''; end; end; function TfrmDoc.GetNextRedoText : String; //just returns the description of the next redo begin try if CanRedo then begin Result := Document.UndoManager.RedoAction[Document.UndoManager.RedoCount-1].Description; end; except Result := ''; end; end; procedure TfrmDoc.popViewMainPopup(Sender: TObject); var bEnabled : Boolean; begin try popMainCut.Enabled := (rtfDoc.SelectionStart <> rtfDoc.SelectionEnd); popMainDelete.Enabled := popMainCut.Enabled; popMainCopy.Enabled := popMainCut.Enabled; //popMainUndo.Enabled := Document.CanUndo; //popMainRedo.Enabled := Document.CanRedo; popMainUndo.Enabled := Document.UndoManager.CanUndo; popMainRedo.Enabled := Document.UndoManager.CanRedo; // Kin 190997 popMainPaste.Enabled := Clipboard.HasFormat(CF_TEXT); popMainSmartPaste.Enabled := popMainPaste.Enabled; //Convert Menu Options bEnabled := (SelLength > 0); mnuRelToAbs.Enabled := bEnabled; mnuAbsToRel.Enabled := bEnabled; mnuConvertLower.Enabled := bEnabled; mnuConvertUpper.Enabled := bEnabled; mnuTable.Enabled := bEnabled; mnuBList.Enabled := bEnabled; except end; try //Macros mnuMacros.Enabled := False; SetupMacroMenu; except end; end; procedure TfrmDoc.PreviewImageClick(Sender : TObject); begin rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength); PreviewImage(''); end; procedure TfrmDoc.popMainUndoClick(Sender: TObject); begin DocUndo; end; procedure TfrmDoc.popMainRedoClick(Sender: TObject); begin DocRedo; end; procedure TfrmDoc.popMainCutClick(Sender: TObject); begin DocCut; end; procedure TfrmDoc.popMainCopyClick(Sender: TObject); begin DocCopy; end; procedure TfrmDoc.popMainPasteClick(Sender: TObject); begin DocPaste; end; procedure TfrmDoc.popMainDeleteClick(Sender: TObject); begin DocDelete; end; function TfrmDoc.GetDocLength: Integer; begin Result := Document.Length; end; { Form Elements } procedure TfrmDoc.FormCheckBox; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmCheckBox, frmCheckBox); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmCheckBox.sTag := SelText; end; frmCheckBox.ShowModal; if Length(frmCheckBox.sTag) > 0 then AddText(frmCheckBox.sTag, '', False); frmCheckBox.free; end; procedure TfrmDoc.FormTextBox; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmFText, frmFText); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmFText.sTag := SelText; end; frmFText.ShowModal; if Length(frmFText.sTag) > 0 then AddText(frmFText.sTag, '', False); frmFText.free; end; procedure TfrmDoc.FormHidden; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmHidden, frmHidden); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmHidden.sTag := SelText; end; frmHidden.ShowModal; if Length(frmHidden.sTag) > 0 then AddText(frmHidden.sTag, '', False); frmHidden.free; end; procedure TfrmDoc.FormPassword; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmPassword, frmPassword); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmPassword.sTag := SelText; end; frmPassword.ShowModal; if Length(frmPassword.sTag) > 0 then AddText(frmPassword.sTag, '', False); frmPassword.free; end; procedure TfrmDoc.FormRadio; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmRadio, frmRadio); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmRadio.sTag := SelText; end; frmRadio.ShowModal; if Length(frmRadio.sTag) > 0 then AddText(frmRadio.sTag, '', False); frmRadio.free; end; procedure TfrmDoc.FormReset; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmReset, frmReset); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmReset.sTag := SelText; end; frmReset.ShowModal; if Length(frmReset.sTag) > 0 then AddText(frmReset.sTag, '', False); frmReset.free; end; procedure TfrmDoc.FormSubmit; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmSubmit, frmSubmit); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmSubmit.sTag := SelText; end; frmSubmit.ShowModal; if Length(frmSubmit.sTag) > 0 then AddText(frmSubmit.sTag, '', False); frmSubmit.free; end; procedure TfrmDoc.FormTextArea; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmTextArea, frmTextArea); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmTextArea.sTag := SelText; end; frmTextArea.ShowModal; if Length(frmTextArea.sTag) > 0 then AddText(frmTextArea.sTag, '', False); frmTextArea.free; end; procedure TfrmDoc.FormList; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmList, frmList); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmList.sTag := SelText; end; if frmList.ShowModal = mrOk Then begin if Length(frmList.sTag) > 0 then AddText(frmList.sTag, '', False); end; frmList.free; end; procedure TfrmDoc.FormImage; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmFImage, frmFImage); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmFImage.sTag := SelText; end; if frmFImage.ShowModal = mrOk Then begin if Length(frmFImage.sTag) > 0 then AddText(frmFImage.sTag, '', False); end; frmFImage.free; end; procedure TfrmDoc.FormWizard; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmFormWiz, frmFormWiz); finally Screen.Cursor := crDefault; end; if frmFormWiz.Showmodal = mrOk then begin if Length(frmFormWiz.sTag) > 0 then AddText(frmFormWiz.sTag, '', False); end; frmFormWiz.Free; end; procedure TfrmDoc.FormShow(Sender: TObject); begin UpdateTagColors; if not(bSetup) then Close else HotDogSound(INI_SOUNDS_OPEN); end; { Spelling } procedure TfrmDoc.CheckSpelling; var bOneWord : Boolean; begin bOneWord := False; try if SelLength > 0 then bOneWord := True; Screen.Cursor := crHourglass; //Create the spelling stuff fist time run if slSpellAddlist = nil then begin sID := SSCE_OpenSession; sID := SSCE_GetSID; slSpellAddList := TStringList.Create; end; Application.CreateForm(TfrmSpell, frmSpell); finally Screen.Cursor := crDefault; end; frmSpell.ShowModal; frmSpell.Free; if frmSpell.ModalResult = mrOK then begin if bOneWord then MessageDlg('HotDog has finished checking the spelling of the selected block.', mtInformation, [mbOK], 0) else MessageDlg('HotDog has finished checking the spelling in this document.', mtInformation, [mbOK], 0); end; SetSelection(SelStart, 0); end; function TfrmDoc.GetNextSpellWord; var iStart{, iEnd}: Integer; {Hint} tElement: Variant; sWord: String; setWhite: Characters; sChar: String; begin setWhite := [#32, #13, #10, #9]; (*',', '.', '?', '(', '{', '[', ']', '}', ')', '+', '=', '~', '!', '#', '$', '%', '^', '&', '*', '@', ':', ';', '`', '\', '/', '"', '*', '<', '>'];*) Result := ''; repeat if iSpellPos < iSpellEnd then begin tElement := Document.GetElementAt(iSpellPos, iStart); if (tElement.Type = HTMLSYNTAXELEMENT_TEXT) then begin //sWord := GetWordAtPos(iSpellPos, iStart, iEnd) sChar := Document.GetTextRange(iSpellPos, iSpellPos + 1); while not(sChar[1] in setWhite) do begin sWord := sWord + Document.GetTextRange(iSpellPos, iSpellPos + 1); Inc(iSpellPos); end; end else iSpellPos := iStart + tElement.Length; end; until (iSpellPos >= iSpellEnd) or (tElement.Type = HTMLSYNTAXELEMENT_TEXT); if iSpellPos >= iSpellEnd then Result := '__SPELL_NO_MORE_' else Result := sWord; //iSpellPos := iEnd; {Hint} end; procedure TfrmDoc.SelectSpellWord; begin rtfDoc.SelectWordAtPos(iSpellPos - 1); end; procedure TfrmDoc.CorrectSpellWord(sWord: String); begin SelText := sWord; end; procedure TfrmDoc.DocAbsToRel; var //lBackTo: Integer; {Hint} bDone: Boolean; lStart: Integer; sToChange: String; bOnce: Boolean; iTagStart, iTagEnd: Integer; sNewTag: String; begin if not(FileExists(sDocFileName)) then begin if MessageDlg('This document must be saved before relative links can be created. Do you want to save the document now?', mtInformation, [mbYes, mbNo], 0) = mrYes then Save; end; if FileExists(sDocFileName) then begin If Length(SelText) = 0 Then begin //lBackTo := SelStart; {Hint} rtfDoc.SetSelection(0, 0); end; {else bOnce := True;} {Hint} lStart := SelStart; bDone := False; bOnce := False; // Sav 13-09-97 while not(bDone) do begin //If something wasn't already highlighted //then go find it If not(bOnce) then begin //Find(sString: String; iStart: Integer; bCase: Boolean; bWholeWord: Boolean): LongInt; iTagStart := Find('file:///', lStart, False, False); //Cheat a bit {ltemp = Len(MainForm.ActiveForm.txtDoc.selText) If ltemp > 0 Then MainForm.ActiveForm.txtDoc.selStart = MainForm.ActiveForm.txtDoc.selStart + 1 MainForm.ActiveForm.txtDoc.selLength = ltemp MainForm.ActiveForm.txtDoc.Span DQ, True, True End If} if iTagStart > -1 then iTagEnd := Find('"', iTagStart, False, False); end; if (iTagStart > -1) and (iTagEnd > -1) then begin //lStart := iTagStart; sToChange := Document.GetTextRange(iTagStart, iTagEnd); sNewTag := AbsoluteToRelative(sDocFileName, UrlToFile(sToChange)); Document.ReplaceText(iTagStart, Length(sToChange), sNewTag); lStart := iTagStart + Length(sNewTag); if bOnce then bDone := True; end else bDone := True; end; end; end; procedure TfrmDoc.DocRelToAbs; var sCurrRef: String; //The current reference sOutRef : String; //New ref sDocDir: String; //The directory the doc lives in sResult: String; begin if not(FileExists(sDocFileName)) then begin if MessageDlg('This document must be saved before relative links can be created. Do you want to save the document now?', mtInformation, [mbYes, mbNo], 0) = mrYes then Save; end; if FileExists(sDocFileName) then begin if SelText = '' Then MessageDlg('Please highlight the reference you wish to change.', mtError, [mbOK], 0) else begin sDocDir := ExtractFileDir(sDocFileName); sCurrRef := SelText; if Copy(sCurrRef, 1, 8) = 'file:///' then sCurrRef := URLToFile(sCurrRef); if (Pos('|', sCurrRef) > 0) or (Pos(':', sCurrRef) > 0) then MessageDlg('This does not appear to be a relative reference.', mtError, [mbOK], 0) else begin sOutRef := RelativeToAbsolute(FilePath(sDocDir, 'kaiser.html'), sCurrRef); //No checking of this result yet... if sCurrRef[1] = '"' then sResult := '"' + (FileToURL(sOutRef)) + '"' else sResult := FileToURL(sOutRef); end; if Length(sResult) > 0 Then SelText := sResult else MessageDlg('HotDog couldn''t convert this reference.', mtError, [mbOK], 0); end; end; end; procedure TfrmDoc.timAutoSaveTimer(Sender: TObject); begin AutoSave; end; procedure TfrmDoc.AutoSave; begin if FileExists(sDocFileName) then begin Status('AutoSaving Document...'); Save; Status('None'); end; end; procedure TfrmDoc.DocProperties; begin Screen.Cursor := crHourglass; Application.CreateForm(TfrmDocProperties, frmDocProperties); try frmDocProperties.sDocFileName := sDocFileName; frmDocProperties.sBodyTag := GetTag(Document.Text, '<BODY', '>'); frmDocProperties.sHeadTag := GetTagGuts(Document.Text, '<HEAD>', '</HEAD>'); frmDocProperties.ShowModal; finally Screen.Cursor := crDefault; frmDocProperties.Free; end; end; procedure TfrmDoc.DocMeta; begin Screen.Cursor := crHourglass; Application.CreateForm(TfrmMeta, frmMeta); try frmMeta.sDocFileName := sDocFileName; frmMeta.sBodyTag := GetTag(Document.Text, '<BODY', '>'); frmMeta.sHeadTag := GetTagGuts(Document.Text, '<HEAD>', '</HEAD>'); frmMeta.ShowModal; finally frmMeta.Free; Screen.Cursor := crDefault; end; end; procedure TfrmDoc.DocColor; begin try // Showmessage(seltext); finally end; end; //Can't do this yet - kin procedure TfrmDoc.SetFileFormat(DocType: DocEOLType); begin Document.EOLType := DocType; if DocType = EOLType_CRLF then spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpWIN') //spdFormat.Caption := 'WIN' else if DocType = EOLType_LF then spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpUNIX') //spdFormat.Caption := 'UNIX' else if DocType = EOLTYPE_CR then spdFormat.glyph.LoadFromResourceName(hInstance, 'bmpMAC'); //spdFormat.Caption := 'MAC'; end; procedure TfrmDoc.ToggleFileFormat; var DocType: DocEOLType; begin DocType := DocEOLType(Document.EOLType); if DocType = EOLType_CR then DocType := EOLType_CRLF else DocType := DocEOLType(Ord(DocType) + 1); SetFileFormat(DocType); end; procedure TfrmDoc.DocInsertTarget; begin try Screen.Cursor := crHourglass; Application.CreateForm(TfrmInternalLink, frmInternalLink); finally Screen.Cursor := crDefault; end; if SelLength > 0 then begin frmInternalLink.sTag := SelText; end; frmInternalLink.ShowModal; if Length(frmInternalLink.sTag) > 0 then AddText(frmInternalLink.sTag, '', False); frmInternalLink.free; end; procedure TfrmDoc.PartnerButton; var tmpINI: TIniFile; sText: String; begin tmpINI := TIniFile.Create(Filepath(tOptions.AutoDownloaderDir , 'Partner.ini')); try //'<A HREF="http://www.hotfiles.com"><IMG SRC="http://www.sausage.com/zdbutton.gif"></A>', sText := '<A HREF="'; sText := sText + tmpIni.ReadString('Details', 'URL', ''); sText := sText + '"><IMG SRC="'; sText := sText + tmpIni.ReadString('Details', 'Image URL', ''); sText := sText + '" BORDER=0>'; AddText(sText, '</A>', True); finally tmpIni.Free; end; end; procedure TfrmDoc.LoadSyntaxColours(Document : THTMLEditView); begin if tOptions.ColorTextBack <> '' then Document.FormatBackcolor[1] := HTMLToColor(tOptions.ColorTextBack); if tOptions.ColorTextText <> '' then Document.FormatTextcolor[1] := HTMLToColor(tOptions.ColorTextText); if tOptions.ColorTextStyle > -1 then Document.FormatStyle[1] := tOptions.ColorTextStyle; if tOptions.ColorOperatorBack <> '' then Document.FormatBackcolor[2] := HTMLToColor(tOptions.ColorOperatorBack); if tOptions.ColorOperatorText <> '' then Document.FormatTextcolor[2] := HTMLToColor(tOptions.ColorOperatorText); if tOptions.ColorOperatorStyle > -1 then Document.FormatStyle[2] := tOptions.ColorOperatorStyle; if tOptions.ColorErrorBack <> '' then Document.FormatBackcolor[3] := HTMLToColor(tOptions.ColorErrorBack); if tOptions.ColorErrorText <> '' then Document.FormatTextcolor[3] := HTMLToColor(tOptions.ColorErrorText); if tOptions.ColorErrorStyle > -1 then Document.FormatStyle[3] := tOptions.ColorErrorStyle; if tOptions.ColorTagBack <> '' then Document.FormatBackcolor[4] := HTMLToColor(tOptions.ColorTagBack); if tOptions.ColorTagText <> '' then Document.FormatTextcolor[4] := HTMLToColor(tOptions.ColorTagText); if tOptions.ColorTagStyle > -1 then Document.FormatStyle[4] := tOptions.ColorTagStyle; if tOptions.ColorAttributeBack <> '' then Document.FormatBackcolor[5] := HTMLToColor(tOptions.ColorAttributeBack); if tOptions.ColorAttributeText <> '' then Document.FormatTextcolor[5] := HTMLToColor(tOptions.ColorAttributeText); if tOptions.ColorAttributeStyle > -1 then Document.FormatStyle[5] := tOptions.ColorAttributeStyle; if tOptions.ColorCommentBack <> '' then Document.FormatBackcolor[6] := HTMLToColor(tOptions.ColorCommentBack); if tOptions.ColorCommentText <> '' then Document.FormatTextcolor[6] := HTMLToColor(tOptions.ColorCommentText); if tOptions.ColorCommentStyle > -1 then Document.FormatStyle[6] := tOptions.ColorCommentStyle; if tOptions.ColorStringBack <> '' then Document.FormatBackcolor[7] := HTMLToColor(tOptions.ColorStringBack); if tOptions.ColorStringText <> '' then Document.FormatTextcolor[7] := HTMLToColor(tOptions.ColorStringText); if tOptions.ColorStringStyle > -1 then Document.FormatStyle[7] := tOptions.ColorStringStyle; if tOptions.ColorIntegerBack <> '' then Document.FormatBackcolor[8] := HTMLToColor(tOptions.ColorIntegerBack); if tOptions.ColorIntegerText <> '' then Document.FormatTextcolor[8] := HTMLToColor(tOptions.ColorIntegerText); if tOptions.ColorIntegerStyle > -1 then Document.FormatStyle[8] := tOptions.ColorIntegerStyle; if tOptions.ColorEnumBack <> '' then Document.FormatBackcolor[9] := HTMLToColor(tOptions.ColorEnumBack); if tOptions.ColorEnumText <> '' then Document.FormatTextcolor[9] := HTMLToColor(tOptions.ColorEnumText); if tOptions.ColorEnumStyle > -1 then Document.FormatStyle[9] := tOptions.ColorEnumStyle; if tOptions.ColorColorBack <> '' then Document.FormatBackcolor[10] := HTMLToColor(tOptions.ColorColorBack); if tOptions.ColorColorText <> '' then Document.FormatTextcolor[10] := HTMLToColor(tOptions.ColorColorText); if tOptions.ColorColorStyle > -1 then Document.FormatStyle[10] := tOptions.ColorColorStyle; if tOptions.ColorURLBack <> '' then Document.FormatBackcolor[11] := HTMLToColor(tOptions.ColorURLBack); if tOptions.ColorURLText <> '' then Document.FormatTextcolor[11] := HTMLToColor(tOptions.ColorURLText); if tOptions.ColorURLStyle > -1 then Document.FormatStyle[11] := tOptions.ColorURLStyle; if tOptions.ColorInvisibleBack <> '' then Document.FormatBackcolor[12] := HTMLToColor(tOptions.ColorInvisibleBack); if tOptions.ColorInvisibleText <> '' then Document.FormatTextcolor[12] := HTMLToColor(tOptions.ColorInvisibleText); if tOptions.ColorInvisibleStyle > -1 then Document.FormatStyle[12] := tOptions.ColorInvisibleStyle; if tOptions.ColorSelectionBack <> '' then Document.FormatBackcolor[13] := HTMLToColor(tOptions.ColorSelectionBack); if tOptions.ColorSelectionText <> '' then Document.FormatTextcolor[13] := HTMLToColor(tOptions.ColorSelectionText); if tOptions.ColorSelectionStyle > -1 then Document.FormatStyle[13] := tOptions.ColorSelectionStyle; //if tOptions.ColorLineNoText <> '' then // Document.FormatTextcolor[14] := HTMLToColor(tOptions.ColorLineNoText); if tOptions.ColorLineNoStyle > -1 then Document.FormatStyle[14] := tOptions.ColorLineNoStyle; //if tOptions.ColorCollapsedBack <> '' then // Document.FormatBackcolor[15] := HTMLToColor(tOptions.ColorCollapsedBack); //if tOptions.ColorCollapsedText <> '' then // Document.FormatTextcolor[15] := HTMLToColor(tOptions.ColorCollapsedText); if tOptions.ColorCollapsedStyle > -1 then Document.FormatStyle[15] := tOptions.ColorCollapsedStyle; //if tOptions.ColorWhiteSpaceBack <> '' then // Document.Backcolor := HTMLToColor(tOptions.ColorWhiteSpaceBack); //if tOptions.ColorWhiteSpaceText <> '' then // Document.TextColor := HTMLToColor(tOptions.ColorWhiteSpaceText); end; procedure TfrmDoc.spdSyntaxClick(Sender: TObject); begin If (spdSyntax.Down) then rtfDoc.HighlightStyle := HTMLEDITVIEW_SYNTAX // kin 190997 else begin if (spdTag.Down) then rtfDoc.HighlightStyle := HTMLEDITVIEW_TAGS else rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX; end; UpdateTagColors; end; procedure TfrmDoc.spdTagClick(Sender: TObject); begin If spdSyntax.Down then rtfDoc.HighlightStyle := HTMLEDITVIEW_SYNTAX // kin 190997 else begin IF spdTag.Down then rtfDoc.HighlightStyle := HTMLEDITVIEW_TAGS else rtfDoc.HighlightStyle := HTMLEDITVIEW_NOTAGSYNTAX; end; //UpdateTagColors; end; procedure TfrmDoc.spdWordWrapClick(Sender: TObject); begin rtfDoc.WordWrap := spdWordWrap.Down; end; procedure TfrmDoc.spdFieldsClick(Sender: TObject); begin rtfDoc.DisplayAll := spdFields.Down; end; procedure TfrmDoc.spdInsertClick(Sender: TObject); begin rtfDoc.Overwrite := spdInsert.Down; end; procedure TfrmDoc.spdFormatClick(Sender: TObject); begin ToggleFileFormat; end; function TfrmDoc.PublishFields : Integer; var sText: String; iChanges : Integer; begin iChanges := 0; sText := PublishText(Document.Text, 'PUBLISH', sDocFileName, iChanges); Result := iChanges; if (Length(sText) > 0) and (sText <> Document.Text) then Document.Text := sText; {else MessageDlg('No Template fields found.', mtInformation, [mbOK], 0);} end; procedure TfrmDoc.PublishAutoFields; var sText: String; iChanges : Integer; begin iChanges := 0; sText := PublishText(Document.Text, 'CREATE', sDocFileName, iChanges); if (Length(sText) > 0) and (sText <> Document.Text) then Document.Text := sText; end; procedure TfrmDoc.InsertPublishField; begin application.createform(TfrmPublishField, frmPublishField); if frmpublishfield.ShowModal = mrOK then addtext(frmpublishfield.PublishField, '', true); end; function TfrmDoc.GetTagAtScreenCoords(tPos: TPoint): String; var tElement: Variant; iStart: Integer; //iEnd: Integer; iPos: Integer; P{, Q}: TPoint; {Hint} begin Result := ''; //P := rtfDoc.ScreenToClient(tPos); P := tPos; Windows.ScreenToClient(rtfDoc.HWnd, P); iPos := rtfDoc.FindPositionFromPoint(P.X, P.Y); if iPos < Document.Length then begin tElement := Document.GetElementAt(iPos, iStart); if tElement.Type = HTMLSYNTAXELEMENT_TAG then begin Result := Document.GetTextRange(iStart, iStart + tElement.Length); end; end; end; procedure TfrmDoc.popEditColorClick(Sender: TObject); var dlgColour: TfrmColorPicker; CurrentColor : TColor; begin dlgColour := TfrmColorPicker.create(nil); try CurrentColor := HTMLToColor(SelText); dlgColour.SetDefaultColour(CurrentColor); if dlgColour.Showmodal = idOK then begin CurrentColor := dlgColour.color; SelText := '#' + GetHexColourStr(CurrentColor); end; finally dlgcolour.free; Application.OnShowhint := MainForm.AppOnShowHint; end; end; function TfrmDoc.GetNextWordPos(iPos : Integer) : Integer; begin result := Document.GetNextWordPos(iPos); end; function TfrmDoc.GetPrevWordPos(iPos : Integer) : Integer; begin result := Document.GetPrevWordPos(iPos); end; function TfrmDoc.GetNextLinePos(iPos : Integer) : Integer; begin result := Document.GetNextLinePos(iPos); end; function TfrmDoc.GetPrevLinePos(iPos : Integer) : Integer; begin result := Document.GetPrevLinePos(iPos); end; procedure TfrmDoc.ReplaceText(iStartPos, iLength : Integer; sReplaceText : String); begin Document.ReplaceText(iStartPos, iLength, sReplaceText); end; procedure TfrmDoc.Reparse; begin Document.Reparse; end; procedure TfrmDoc.spdGutterClick(Sender: TObject); begin try rtfDoc.Enabled := False; if spdGutter.Down then begin if tOptions.LineGutter then begin rtfDoc.IndentSize := iBookmarkWidth + (tOptions.LineGutterNumber * rtfDoc.GutterFontWidth);//LINE_GUTTER_SIZE; rtfDoc.ShowLineNumber := True; end else begin rtfDoc.IndentSize := iBookmarkWidth + rtfDoc.GutterFontWidth; //NO_LINE_GUTTER_SIZE; rtfDoc.ShowLineNumber := False; end; rtfDoc.LeftMarginVisible := True; end else begin rtfDoc.IndentSize := rtfDoc.GutterFontWidth;//NO_GUTTER_SIZE; rtfDoc.ShowLineNumber := False; rtfDoc.LeftMarginVisible := False; end; finally rtfDoc.Enabled := True; end; end; function TfrmDoc.GenerateTable(sTabledata : String) : String; var i,j : Integer; strRows : TStringList; strCells : TStringList; sHTML : String; const OPENROW : String = '<TR>'; CLOSEROW : String = '</TR>'; OPENCELL : String = '<TD>'; CLOSECELL : String = '</TD>'; TAB = #9; begin strRows := TStringList.Create; strCells := TStringList.Create; sHTML := '<TABLE BORDER="1">' + #13#10; try ParseLine(sTabledata, #13#10, strRows); For i := 0 to strRows.Count - 1 do begin sHTML := sHTML + Tab + OPENROW + #13#10; ParseLine(strRows.Strings[i], Tab, strCells); For j := 0 to strCells.Count -1 do begin sHTML := sHTML + Tab + Tab + OPENCELL + strCells.Strings[j] + CLOSECELL + #13#10; end; sHTML := sHTML + Tab + CLOSEROW + #13#10; end; sHTML := sHTML + '</TABLE>' + #13#10; except end; result := sHTML; end; procedure TfrmDoc.popMainHREFClick(Sender: TObject); begin mOpenFileName(popMainHref.Hint); end; procedure TfrmDoc.PasteFromClipboard(Key : word); var iRow : Integer; begin iRow := 0; Case Key of 49 : iRow := 1; 50 : iRow := 2; 51 : iRow := 3; 52 : iRow := 4; 53 : iRow := 5; 54 : iRow := 6; 55 : iRow := 7; 56 : iRow := 8; 57 : iRow := 9; end; if MainForm.strClipboard.Objects[1,iRow] <> Nil then SelText := (MainForm.strClipboard.Objects[1,iRow] as TClipboardString).sItem; end; procedure TfrmDoc.CopyToClipboard(Key : word); var iRow : Integer; newString : TClipboardString; begin iRow := 0; Case Key of 49 : iRow := 1; 50 : iRow := 2; 51 : iRow := 3; 52 : iRow := 4; 53 : iRow := 5; 54 : iRow := 6; 55 : iRow := 7; 56 : iRow := 8; 57 : iRow := 9; end; if Pos(#13#10, SelText) > 0 then MainForm.strClipboard.Cells[1,iRow] := Copy(SelText, 0, Pos(#13#10, SelText)-1) else MainForm.strClipboard.Cells[1,iRow] := SelText; newString := TClipboardString.Create; newString.sItem := SelText; MainForm.strClipboard.Objects[1,iRow] := newString; end; procedure TfrmDoc.ShowThesaurus; begin Application.CreateForm(TfrmThesaurus, frmThesaurus); if SelLength = 0 then rtfDoc.SelectWordAtPos(SelStart); frmThesaurus.sWord := SelText; //Status('Searching for selected word. This may take a few moments.'); if frmThesaurus.ShowModal = mrOk then begin SelText := frmThesaurus.sWord; end; frmThesaurus.Release; end; function TfrmDoc.GetBookmarks : String; var i : Integer; iDocumentCount : Integer; begin iDocumentCount := rtfDoc.BookmarkCount -1; for i := 0 to iDocumentCount do begin Result := Result + rtfDoc.BookmarkName[i] + ','; end; end; procedure TfrmDoc.GotoBookmark(sBookmark : String); begin try rtfDoc.GotoBookmark(sBookMark); except end; end; function TfrmDoc.GetCurrentLine : Integer; var iCol, iRow : Integer; begin Result := 0; try rtfDoc.FindCoordinateFromPosition(SelEnd, iCol, iRow); result := iRow + 1; except end; end; function TfrmDoc.GetLinePosition(iLine : Integer) : Integer; begin result := -1; if (iLine > -1) and (iLine < Document.LineCount) then begin result := Document.LinePos(iLine); end; end; function TfrmDoc.GetNextElementPos(iType : Integer; iStart: Integer): Integer; var //sResult: String; //-- Sav hint iCount: Integer; tElement: Variant; begin Result := -1; tElement := Document.GetElementAt(iStart, iStart); iStart := iStart + tElement.Length; iCount := iStart; while iCount < Document.Length - 1 do begin try tElement := Document.GetElementAt(iCount, iStart); if tElement.Type <> iType then iCount := iCount + tElement.Length else begin Result := iStart; if Result > -1 then iCount := Document.Length else iCount := iCount + tElement.Length - 1; end; except end; end; end; function TfrmDoc.GetPreviousElementPos(iType : Integer; iStart : Integer) : Integer; var //sResult: String; //-- Sav hint iCount: Integer; tElement: Variant; begin Result := -1; tElement := Document.GetElementAt(iStart, iStart); Dec(iStart); iCount := iStart; while iCount > 0 do begin try tElement := Document.GetElementAt(iCount, iStart); if tElement.Type <> iType then iCount := iCount - tElement.Length else begin Result := iStart; if Result > -1 then iCount := 0 else iCount := iCount - (tElement.Length + 1); end; except end; end; end; procedure TfrmDoc.FindMatchingCharacter(iPosition : Integer); var //tElement: Variant; iStart : Integer; begin iStart := rtfDoc.GetMatchChar(iPosition); rtfDoc.SetSelection(iStart, iStart); end; function TfrmDoc.DocSaveAsRemote: Boolean; var dlgRemote: TfrmRemoteDlg; sFile: String; begin dlgRemote := TfrmRemoteDlg.Create(Application); try dlgRemote.DlgType := DlgSave; dlgRemote.Filter := HTML_FILTER_; dlgRemote.DefaultExt := 'htm'; dlgRemote.FilterIndex := 0; {-= Create a tmp file and write to it... =-} sFile := FilePath(GetTempDirectory, ('~hd1201.zzz')); Document.SaveToFile(sFile); dlgRemote.FileName := sFile; if dlgRemote.ShowModal <> idCancel then begin bInternet := True; sInternetFileName := dlgRemote.RemoteFileName; tInternetServer := dlgRemote.InternetServer; sDocFileName := GetTempDirectory; sDocFileName := FilePath(sDocFileName, ExtractFileName(dlgRemote.FileName)); {MessageDlg('Remote file ' + sInternetFileName + ' succesfully saved.', mtConfirmation, [mbOK], 0);} Caption := dlgRemote.RemoteFileName; //MainForm.Draw(True); bDocDirty := False; Result := True; MDI.UpdateTabName(Self, sInternetFileName); //tProject.UpdateSniffer(MDI.MDIChildIndex(Self), sInternetFileName); if tOptions.SaveBrowserRefresh then DocPreviewWithLastBrowser; HideToolbarShit(False); end else Result := False; finally dlgRemote.Free; end; end; procedure TfrmDoc.DocBody; var strBody : TStringList; sResult : String; iPos : Integer; begin strBody := TStringList.Create; try SniffText(Text, '<body', '>', strBody, True); if strBody.Count >= 0 then try sResult := strBody.Strings[0]; iPos := StrToInt(copy(sResult, 0, (Pos(',', sResult)-1)));// + Length(sResult); sResult := copy(sResult, (Pos(',', sResult)+1), Length(sResult)); iPos := iPos + Length(sResult); SetCursorPos(iPos); except SetCursorPos(Find('<BODY', 0, False, False) + 7); end; finally strBody.Free; end; end; function TfrmDoc.GetDocumentStorageHandle: HGlobal; var hMem: HGlobal; begin Result := 0; if rtfDoc.SaveExtraInfoToMemory(hMem) then Result := hMem; end; procedure TfrmDoc.LoadStorageMemory(hMem: HGlobal); begin rtfDoc.LoadExtraInfoFromMemory(hMem, GlobalSize(hMem)); end; procedure TfrmDoc.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var pt : TPoint; begin //ShowMessage(Format('%d', [SelStart])); // -- Test if (ssCtrl in Shift) and (Key = 9) then GotFocus //windows right click key else if (key = 93) then begin rtfDoc.ScrollCaretToView; rtfDoc.FindPointFromPosition(SelEnd, pt.X, pt.Y); pt.Y := pt.Y - rtfDoc.EditFont.Height; rtfDoc.HideSyntaxPicker; //pt := ClientToScreen(pt); MainViewRightClick(pt.x, pt.y); end //Delete key does not automatically make the document dirty else if (Key = 8) or (key = 46) then begin bDocDirty := True; MainForm.DirtyBird(True); HideToolbarShit(False); //MainForm.HideShit; end; end; procedure TfrmDoc.popHideGutterClick(Sender: TObject); begin spdGutter.Down := False; spdGutterClick(Self); end; procedure TfrmDoc.popShowPawsClick(Sender: TObject); begin rtfDoc.GutterBitmapVisible := Not(rtfDoc.GutterBitmapVisible); end; procedure TfrmDoc.popLine0Click(Sender: TObject); begin rtfDoc.IndentSize := iBookMarkWidth + rtfDoc.GutterFontWidth; tOptions.LineGutter := False; rtfDoc.ShowLineNumber := False; end; procedure TfrmDoc.popLine1Click(Sender: TObject); begin tOptions.LineGutterNumber := 1; rtfDoc.IndentSize := iBookMarkWidth + (1 * rtfDoc.GutterFontWidth); tOptions.LineGutter := True; rtfDoc.ShowLineNumber := True; end; procedure TfrmDoc.popLine2Click(Sender: TObject); begin tOptions.LineGutterNumber := 2; rtfDoc.IndentSize := iBookMarkWidth + (2 * rtfDoc.GutterFontWidth); tOptions.LineGutter := True; rtfDoc.ShowLineNumber := True; end; procedure TfrmDoc.popLine3Click(Sender: TObject); begin tOptions.LineGutterNumber := 3; rtfDoc.IndentSize := iBookMarkWidth + (3 * rtfDoc.GutterFontWidth); tOptions.LineGutter := True; rtfDoc.ShowLineNumber := True; end; procedure TfrmDoc.popLine4Click(Sender: TObject); begin tOptions.LineGutterNumber := 4; rtfDoc.IndentSize := iBookMarkWidth + (4 * rtfDoc.GutterFontWidth); tOptions.LineGutter := True; rtfDoc.ShowLineNumber := True; end; procedure TfrmDoc.popPSPClick(Sender: TObject); var sFileName : String; begin rtfDoc.SetSelection(tCurrentElement.iStart, tCurrentElement.iLength); sFileName := GetAttribute(SelText,'SRC'); if Length(sFileName) > 0 then begin if Pos('file://', sFileName) > 0 then sFileName := URLToFile(sFileName); sFileName := RelativeToAbsolute(sDocFileName, sFileName); if FileExists(sFilename) then RunPaintShop(sFileName) else MessageDlg('The image ' + sFileName + ' could not be found.', mtError, [mbOK], 0); end; end; procedure TfrmDoc.mnuRelToAbsClick(Sender: TObject); begin try DocRelToAbs; except end; end; procedure TfrmDoc.mnuAbsToRelClick(Sender: TObject); begin try DocAbsToRel; except end; end; procedure TfrmDoc.mnuConvertLowerClick(Sender: TObject); begin try DocConvertCase(False); except end; end; procedure TfrmDoc.mnuConvertUpperClick(Sender: TObject); begin try DocConvertCase(True); except end; end; procedure TfrmDoc.mnuTagsLowercaseClick(Sender: TObject); begin try DocConvertTagCase(False, False); except end; end; procedure TfrmDoc.mnuTagsUppercaseClick(Sender: TObject); begin try DocConvertTagCase(False, True); except end; end; procedure TfrmDoc.mnuTableClick(Sender: TObject); begin try SelText := GenerateTable(SelText); except end; end; procedure TfrmDoc.mnuBListClick(Sender: TObject); begin try InsertList; except end; end; procedure TfrmDoc.SetupMacroMenu; var menNewItem : TMenuItem; pCategory : ^TMenuItem; iCount : Integer; strMacros : TStringList; begin strMacros := TStringList.Create; try //Delete all the existing macro list items while mnuMacros.Count > 0 do mnuMacros.Delete(0); except end; try strMacros.LoadfromFile(sAppPath+'HDMacros.mac'); if strMacros.Count > 0 then begin New(pCategory); pCategory^ := mnuMacros; for iCount := 0 to strMacros.Count -1 do begin menNewItem := TMenuItem.Create(popViewMain); if Pos('{', strMacros.Strings[iCount]) = 0 then begin menNewItem.Caption := strMacros.Strings[iCount]; mnuMacros.Insert(mnuMacros.Count, menNewItem); pCategory^ := menNewItem; end else begin menNewItem.OnClick := MacroMenuClick; menNewItem.Caption := chopafter(chopbefore(strMacros.strings[iCount],'}}{{'),'}{'); pCategory^.Insert(pCategory^.Count, menNewItem); end; mnuMacros.Enabled := True; end; end; finally strMacros.Free; end; end; procedure TfrmDoc.MacroMenuClick(Sender : TObject); var iMacroPos : Integer; strMacros : TStringList; sMacroName : String; begin strMacros := TStringList.Create; try strMacros.LoadfromFile(sAppPath+'HDMacros.mac'); iMacroPos := -1; sMacroName := (Sender as TMenuItem).Caption; repeat inc(iMacroPos); until (pos(('}{'+sMacroName+'}}{{'),strMacros.strings[iMacroPos])>0) or (iMacroPos=strMacros.count-1); if iMacroPos<=strMacros.count-1 then begin strMacros.strings[iMacroPos] := ReplaceString(strMacros.strings[iMacroPos], #30, #13#10); SelText := GetMacroBeforeText(strMacros.strings[iMacroPos]) + SelText + GetMacroAfterText(strMacros.strings[iMacroPos]); SetSelection(SelEnd, 0); end; finally end; end; procedure TfrmDoc.rtfDocRequestURL(Sender: TObject; var bDispatched: WordBool; var strURL: WideString; var bAccepted: WordBool); var sInitialDir : String; begin if tOptions.DlgCurrentDir then sInitialDir := tOptions.LastHTMLDir else sInitialDir := tOptions.DocumentDirectory; DisplayFileDialog(HTML_FILTER_, sInitialDir, bDispatched, strURL, bAccepted); end; procedure TfrmDoc.DisplayFileDialog(sFilter, sInitialDir : String; var Dispatched : WordBool; var Name : WideString; var Accepted : WordBool); begin Dispatched := True; Name := ShowDialogs(MainForm, sFilter, Name, sInitialDir); if Name <> '' then Accepted := True else Accepted := False; end; procedure TfrmDoc.rtfDocRequestFont(Sender: TObject; var bDispatched: WordBool; var strFont: WideString; var bAccepted: WordBool); begin bDispatched := True; bAccepted := False; Application.CreateForm(TfrmFontDlg, frmFontDlg); try frmFontDlg.ShowModal; if frmFontDlg.ModalResult = mrOK then begin bAccepted := True; strFont := frmFontDlg.HTMLFont.Name; end; finally frmFontDlg.Free; end; end; procedure TfrmDoc.rtfDocRequestSound(Sender: TObject; var bDispatched: WordBool; var strSound: WideString; var bAccepted: WordBool); begin DisplayFileDialog(SOUND_FILTER, tOptions.DocumentDirectory, bDispatched, strSound, bAccepted); end; procedure TfrmDoc.rtfDocRequestPicture(Sender: TObject; var bDispatched: WordBool; var strPicture: WideString; var bAccepted: WordBool); var sInitialDir : String; begin if tOptions.DlgCurrentDir then sInitialDir := tOptions.LastGraphicsDir else sInitialDir := tOptions.GraphicsDirectory; DisplayFileDialog(GRAPHICS_FILTER, sInitialDir, bDispatched, strPicture, bAccepted); end; procedure TfrmDoc.rtfDocRequestJava(Sender: TObject; var bDispatched: WordBool; var strJava: WideString; var bAccepted: WordBool); begin DisplayFileDialog(ALLFILES_FILTER, tOptions.DocumentDirectory, bDispatched, strJava, bAccepted); end; procedure TfrmDoc.rtfDocRequestHTML(Sender: TObject; var bDispatched: WordBool; var strHTML: WideString; var bAccepted: WordBool); var sInitialDir : String; begin if tOptions.DlgCurrentDir then sInitialDir := tOptions.LastHTMLDir else sInitialDir := tOptions.DocumentDirectory; DisplayFileDialog(HTML_FILTER_, sInitialDir, bDispatched, strHTML, bAccepted); end; procedure TfrmDoc.rtfDocRequestDirectory(Sender: TObject; var bDispatched: WordBool; var strDirectory: WideString; var bAccepted: WordBool); begin bDispatched := True; bAccepted := False; Application.CreateForm(TfrmDirList, frmDirList); frmDirList.ptDirTree.SelectedPathName := strDirectory; frmDirList.ShowModal; if frmDirList.ModalResult <> mrOk then begin bAccepted := True; strDirectory := frmDirList.ptDirTree.SelectedPathName end; frmDirList.Free; end; procedure TfrmDoc.HideSyntaxPicker; begin rtfDoc.HideSyntaxPicker; end; procedure TfrmDoc.rtfDocSyntaxObjectChanged(Sender: TObject; nType: Smallint; const strPrimary, strSecondary: WideString); begin if Assigned(MainForm.tpnlPSheet) then MainForm.propSheetObjectChanged(Sender, nType, strPrimary, strSecondary); end; procedure TfrmDoc.mnuStripTagsClick(Sender: TObject); begin StripTags; end; procedure TfrmDoc.DisplayGutterPopup(X, Y : Integer); var gutterItems : Array[0..2] of TMenuItem; NumberItems : Array[0..4] of TMenuItem; popGutter : TPopupMenu; P, Q: TPoint; begin gutterItems[0] := NewItem('&Hide Gutter', 0, False, True, popHideGutterClick, 0, 'popShowGutter'); gutterItems[1] := NewItem('&Show &Paws', 0, False, True, popShowPawsClick, 0, 'popShowPaws'); numberItems[0] := NewItem('&Not Shown', 0, False, True, popLine0Click, 0, 'popLine0'); numberItems[1] := NewItem('&1 Number', 0, False, True, popLine1Click, 0, 'popLine1'); numberItems[2] := NewItem('&2 Numbers', 0, False, True, popLine2Click, 0, 'popLine2'); numberItems[3] := NewItem('&3 Numbers', 0, False, True, popLine3Click, 0, 'popLine3'); numberItems[4] := NewItem('&4 Numbers', 0, False, True, popLine4Click, 0, 'popLine4'); if rtfDoc.GutterBitmapVisible then gutterItems[1].Caption := 'Hide &Paws' else gutterItems[1].Caption := 'Show &Paws'; if not(tOptions.LineGutter) then numberItems[0].Checked := True else if tOptions.LineGutterNumber = 1 then numberItems[1].Checked := True else if tOptions.LineGutterNumber = 2 then numberItems[2].Checked := True else if tOptions.LineGutterNumber = 3 then numberItems[3].Checked := True else if tOptions.LineGutterNumber = 4 then numberItems[4].Checked := True; gutterItems[2] := NewSubMenu('&Line Numbers', 0, 'popLineNumbers', numberItems); popGutter := NewPopupMenu(Self, 'popGutter', paLeft, True, gutterItems); P := Point(X, Y); Q := rtfDoc.ClientToScreen(P); popGutter.PopUp(Q.X, Q.Y); Application.ProcessMessages; popGutter.Free; end; procedure TfrmDoc.DocQuickColor(sColor : String); begin //called from quick color form SelText := sColor; end; procedure TfrmDoc.rtfDocRequestColor(Sender: TObject; var bDispatched: WordBool; var Color: Cardinal; var bAccepted: WordBool); var dlgColour: TfrmColorPicker; begin dlgColour := TfrmColorPicker.create(nil); bDispatched := True; try dlgColour.SetDefaultColour(Color); if dlgColour.showmodal = idOK then begin bAccepted := True; Color := dlgColour.color; end; finally dlgcolour.free; Application.OnShowhint := MainForm.AppOnShowHint; end; end; procedure TfrmDoc.WMMOVE(var Message: TWMMOVE); begin inherited; //InvalidateRect(ClientHandle, nil, True); end; procedure TfrmDoc.WMSIZE(var Message: TWMSIZE); begin inherited; spdFormat.Left := panButtons.Width - SpdFormat.Width; lblDocWeight.Left := spdFormat.Left - lblDocWeight.Width; end; procedure TfrmDoc.btnShowButtonsClick(Sender: TObject); begin ResizeRoverToolbar(not spdSyntax.Visible); tOptions.EditorToolbarLarge := spdSyntax.Visible; end; procedure TfrmDoc.RefreshDocumentWeight; var iSize : Integer; begin iSize := CalculateDocumentSize; if iSize < 1024 then lblDocWeight.caption := IntToStr(iSize) + ' Bytes ' else lblDocWeight.Caption := IntToStr(iSize div 1024)+'Kb '; end; procedure TfrmDoc.lblDocWeightMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button = mbLeft then RefreshDocumentWeight; end; procedure TfrmDoc.ResizeRoverToolbar(bLargeView: Boolean); begin if not bLargeView then begin spdSyntax.Visible := False; spdTag.Visible := False; spdGutter.Visible := False; spdWordWrap.Visible := False; spdFields.Visible := False; spdInsert.Visible := False; spdFormat.Visible := False; btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarExpand'); panButtons.Height := 8; btnShowButtons.Height := 8; btnShowButtons.Top := 0; lblDocWeight.Visible := False; //bevDocWeight.Visible := False; end else begin spdSyntax.Visible := True; spdTag.Visible := True; spdGutter.Visible := True; spdWordWrap.Visible := True; spdFields.Visible := True; spdInsert.Visible := True; spdFormat.Visible := True; btnShowButtons.glyph.LoadFromResourceName(hInstance, 'bmpDocToolbarCollapse'); panButtons.Height := 23; btnShowButtons.Top := 1; btnShowButtons.Height := 22; lblDocWeight.Visible := True; //bevDocWeight.Visible := True; end; end; procedure TfrmDoc.popMainSmartPasteClick(Sender: TObject); begin DocPasteLeftAligned; end; end.